1 | <?php |
---|
2 | |
---|
3 | class clj { |
---|
4 | static public function send_mail($result, $mailto, $subject, $content, $headers, $args) { |
---|
5 | |
---|
6 | $ret =clj_send_mail($result, $mailto, $subject, $content, $headers, $args); |
---|
7 | |
---|
8 | if($ret=="") return true ; |
---|
9 | return true ; |
---|
10 | |
---|
11 | // |
---|
12 | return false; // envoie |
---|
13 | return true ; // pas d'envoie |
---|
14 | } |
---|
15 | /************************************ |
---|
16 | * |
---|
17 | *************************************/ |
---|
18 | static public function send_mail_to( $to){ |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | return $to; |
---|
23 | } |
---|
24 | /************************************ |
---|
25 | * |
---|
26 | *************************************/ |
---|
27 | static public function send_mail_subject($cvt_subject){ |
---|
28 | |
---|
29 | return $cvt_subject; |
---|
30 | } |
---|
31 | /************************************ |
---|
32 | * |
---|
33 | *************************************/ |
---|
34 | static public function send_mail_content($content){ |
---|
35 | |
---|
36 | return $content; |
---|
37 | } |
---|
38 | /************************************ |
---|
39 | * |
---|
40 | *************************************/ |
---|
41 | static public function send_mail_headers($headers_init){ |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | return $headers_init; |
---|
46 | } |
---|
47 | |
---|
48 | /* |
---|
49 | * sends an email, using Piwigo specific informations |
---|
50 | * |
---|
51 | * @param: |
---|
52 | * - to: receiver(s) of the mail (list separated by comma). |
---|
53 | * - args: function params of mail function: |
---|
54 | * o from: sender [default value webmaster email] |
---|
55 | * o Cc: array of carbon copy receivers of the mail. [default value empty] |
---|
56 | * o Bcc: array of blind carbon copy receivers of the mail. [default value empty] |
---|
57 | * o subject [default value 'Piwigo'] |
---|
58 | * o content: content of mail [default value ''] |
---|
59 | * o content_format: format of mail content [default value 'text/plain'] |
---|
60 | * o email_format: global mail format [default value $conf_mail['default_email_format']] |
---|
61 | * o theme: template to use [default get_default_theme()] |
---|
62 | * |
---|
63 | * @return boolean (Ok or not) |
---|
64 | * pour mise au point . |
---|
65 | */ |
---|
66 | function cl_pwg_mail($to, $args = array()){ |
---|
67 | global $conf, $conf_mail, $lang_info, $page; |
---|
68 | if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) { |
---|
69 | return true; |
---|
70 | } |
---|
71 | if (!isset($conf_mail)) { |
---|
72 | $conf_mail = get_mail_configuration(); |
---|
73 | } |
---|
74 | if (empty($args['email_format'])) { |
---|
75 | $args['email_format'] = $conf_mail['default_email_format']; |
---|
76 | } |
---|
77 | // Compute root_path in order have complete path |
---|
78 | set_make_full_url(); |
---|
79 | if (empty($args['from'])) { |
---|
80 | $args['from'] = $conf_mail['formated_email_webmaster']; |
---|
81 | } else { |
---|
82 | $args['from'] = format_email('', $args['from']); |
---|
83 | } |
---|
84 | if (empty($args['subject'])) { |
---|
85 | $args['subject'] = 'Piwigo'; |
---|
86 | } |
---|
87 | // Spring cleaning |
---|
88 | $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject'])); |
---|
89 | // Ascii convertion |
---|
90 | $cvt_subject = encode_mime_header($cvt_subject); |
---|
91 | |
---|
92 | if (!isset($args['content'])) { |
---|
93 | $args['content'] = ''; |
---|
94 | } |
---|
95 | |
---|
96 | if (empty($args['content_format'])) { |
---|
97 | $args['content_format'] = 'text/plain'; |
---|
98 | } |
---|
99 | |
---|
100 | if ($conf_mail['send_bcc_mail_webmaster']) { |
---|
101 | $args['Bcc'][] = $conf_mail['formated_email_webmaster']; |
---|
102 | } |
---|
103 | |
---|
104 | if (empty($args['theme'])) { |
---|
105 | $args['theme'] = get_default_theme(); |
---|
106 | } |
---|
107 | |
---|
108 | $headers = 'From: '.$args['from']."\n"; |
---|
109 | $headers.= 'Reply-To: '.$args['from']."\n"; |
---|
110 | |
---|
111 | if (!empty($args['Cc'])) { |
---|
112 | $headers.= 'Cc: '.implode(',', $args['Cc'])."\n"; |
---|
113 | } |
---|
114 | |
---|
115 | if (!empty($args['Bcc'])) { |
---|
116 | $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n"; |
---|
117 | } |
---|
118 | |
---|
119 | $headers.= 'Content-Type: multipart/alternative;'."\n"; |
---|
120 | $headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'."\n"; |
---|
121 | $headers.= ' reply-type=original'."\n"; |
---|
122 | $headers.= 'MIME-Version: 1.0'."\n"; |
---|
123 | $headers.= 'X-Mailer: Piwigo Mailer'."\n"; |
---|
124 | |
---|
125 | // List on content-type |
---|
126 | $content_type_list[] = $args['email_format']; |
---|
127 | if (!empty($conf_mail['alternative_email_format'])) { |
---|
128 | $content_type_list[] = $conf_mail['alternative_email_format']; |
---|
129 | } |
---|
130 | |
---|
131 | $content = ''; |
---|
132 | |
---|
133 | foreach (array_unique($content_type_list) as $content_type) { |
---|
134 | // key compose of indexes witch allow ti cache mail data |
---|
135 | $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme']; |
---|
136 | |
---|
137 | if (!isset($conf_mail[$cache_key])) { |
---|
138 | if (!isset($conf_mail[$cache_key]['theme'])) { |
---|
139 | $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']); |
---|
140 | } |
---|
141 | |
---|
142 | $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl'); |
---|
143 | $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl'); |
---|
144 | |
---|
145 | $conf_mail[$cache_key]['theme']->assign( |
---|
146 | array( |
---|
147 | //Header |
---|
148 | 'BOUNDARY_KEY' => $conf_mail['boundary_key'], |
---|
149 | 'CONTENT_TYPE' => $content_type, |
---|
150 | 'CONTENT_ENCODING' => get_pwg_charset(), |
---|
151 | |
---|
152 | // Footer |
---|
153 | 'GALLERY_URL' => get_gallery_home_url(), |
---|
154 | 'GALLERY_TITLE' => |
---|
155 | isset($page['gallery_title']) ? |
---|
156 | $page['gallery_title'] : $conf['gallery_title'], |
---|
157 | 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', |
---|
158 | 'PHPWG_URL' => PHPWG_URL, |
---|
159 | |
---|
160 | 'TITLE_MAIL' => urlencode(l10n('A comment on your site')), |
---|
161 | 'MAIL' => get_webmaster_mail_address() |
---|
162 | )); |
---|
163 | |
---|
164 | if ($content_type == 'text/html') { |
---|
165 | if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl')) |
---|
166 | { |
---|
167 | $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl'); |
---|
168 | $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css'); |
---|
169 | } |
---|
170 | |
---|
171 | $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl'; |
---|
172 | if (is_file($file)) { |
---|
173 | $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file)); |
---|
174 | $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css'); |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | // what are displayed on the header of each mail ? |
---|
179 | $conf_mail[$cache_key]['header'] = |
---|
180 | $conf_mail[$cache_key]['theme']->parse('mail_header', true); |
---|
181 | |
---|
182 | // what are displayed on the footer of each mail ? |
---|
183 | $conf_mail[$cache_key]['footer'] = |
---|
184 | $conf_mail[$cache_key]['theme']->parse('mail_footer', true); |
---|
185 | } |
---|
186 | |
---|
187 | // Header |
---|
188 | $content.= $conf_mail[$cache_key]['header']; |
---|
189 | |
---|
190 | // Content |
---|
191 | if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html')) { |
---|
192 | $content.= '<p>'. |
---|
193 | nl2br( |
---|
194 | preg_replace("/(http:\/\/)([^\s,]*)/i", |
---|
195 | "<a href='$1$2' class='thumblnk'>$1$2</a>", |
---|
196 | htmlspecialchars($args['content']))). |
---|
197 | '</p>'; |
---|
198 | } |
---|
199 | else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain')) |
---|
200 | { |
---|
201 | // convert html text to plain text |
---|
202 | $content.= strip_tags($args['content']); |
---|
203 | } else { |
---|
204 | $content.= $args['content']; |
---|
205 | } |
---|
206 | |
---|
207 | // Footer |
---|
208 | $content.= $conf_mail[$cache_key]['footer']; |
---|
209 | |
---|
210 | // Close boundary |
---|
211 | $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; |
---|
212 | } |
---|
213 | |
---|
214 | //~ // Close boundary |
---|
215 | //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; |
---|
216 | |
---|
217 | // Undo Compute root_path in order have complete path |
---|
218 | unset_make_full_url(); |
---|
219 | |
---|
220 | return |
---|
221 | trigger_event('send_mail', |
---|
222 | false, /* Result */ |
---|
223 | trigger_event('send_mail_to', get_strict_email_list($to)), |
---|
224 | trigger_event('send_mail_subject', $cvt_subject), |
---|
225 | trigger_event('send_mail_content', $content), |
---|
226 | trigger_event('send_mail_headers', $headers), |
---|
227 | $args |
---|
228 | ); |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | } |
---|
233 | ?> |
---|