source: extensions/Mail_supervisor/include/function_test_send.php @ 8917

Last change on this file since 8917 was 8917, checked in by cljosse, 13 years ago

[Mail_Supervisor] compatibility with piwigo 2.2

File size: 7.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if ( !defined('PHPWG_ROOT_PATH')) 
25{
26  die('Hacking attempt!');
27}
28
29
30
31function test_envoie($message,$group_name,$group_id)
32{
33    global $infos_message,$erreur_message ,$conf,$user,$conf_mail,$mail_donnees,$args,$lang ;
34        $mailto=""; 
35       
36 load_language('plugin.lang', MAIL_SUPERV_PATH);
37 
38//==================================================================================
39if (!isset($infos_message))
40        {
41        $infos_message = "";
42        }
43if (!isset($erreur_message))
44        {
45        $erreur_message = '';
46        }
47if (!isset($mails_donnees))
48        {
49        $mails_donnees = Get_Datas();
50        }               
51if (!isset($conf_mail))
52  {
53        $conf_mail = get_mail_configuration();
54  }
55          if (isset($args))
56  { 
57    $infos_message=memo_var($args);
58  }else{
59        $args = array();
60        }
61//=====================================================================================================
62
63 
64
65$groups=get_liste($group_id);
66
67//=======================================================================================
68  if (count($groups) > 0)
69  {
70       $args['Bcc']=$groups;
71   }   else {
72       $mailto = $conf_mail['formated_email_webmaster']; 
73   } 
74   
75$args['from'] =(function_exists('get_user_language_desc')) ? get_user_language_desc($conf_mail['formated_email_webmaster']):$conf_mail['formated_email_webmaster'];
76$message_html =$message;
77      if (function_exists('get_user_language_desc') and isset($message) and $message <> '')
78        $message = get_user_language_desc($message)."\n\n";
79 
80        //==================================================================
81         $message_texte=sprintf(
82        l10n('Sv_message_texte %s %s %s %s'),
83        format_date( date("Y-m-d H:i:s")),
84                $group_name,
85                $message,
86                $args['from']
87        );     
88        //==================================================================
89        $message_html .= "</br>" . $message . "</br>" . $message_texte;
90
91       
92 //==========================================================================
93
94        $args['subject']="Plugin Piwigo TEST";
95        $args['content']=$message_html;
96                $infos_message .="To :" . $mailto;
97               
98        $ret= pwg_mail($mailto , $args); 
99        if ( $group_name <> '' or $mailto <> '' )
100        {       
101                if ($group_name<>'') {
102                 $infos_message .=  '<br />'.  sprintf( l10n('An information email was sent to group "%s"'), $group_name ).'<br />';
103                        }
104                        if ($mailto <> '') {
105                                $infos_message .=  '<br />'.  sprintf( l10n('Sv_mail_sent_to'), $mailto ).'<br />';
106                                }
107                 
108        }else{
109               $infos_message .='<br />'.l10n('Sv_no_receiver_available') ;
110        }
111
112}
113//===============================================================================================================
114function mail_attachement($args)
115{
116 global $infos_message,$erreur_message ,$conf,$user,$conf_mail,$mail_donnees,$lang ;
117
118    $mails_donnees = Get_Datas();
119          if (!isset($conf_mail))
120  {
121    $conf_mail = get_mail_configuration();
122  }
123
124 load_language('plugin.lang', MAIL_SUPERV_PATH);
125
126                $nom ='piwigo_logo_sombre_214x100.png'; 
127                $fichier=PHPWG_ROOT_PATH.'admin/template/goto/theme/roma/images/piwigo_logo_sombre_214x100.png' ;
128                $typemime='image/jpeg';
129                               
130                $fd = fopen( $fichier, "r" ); 
131                $contenu = fread( $fd, filesize( $fichier ) ); 
132                fclose( $fd ); 
133                $piecejointe  = chunk_split(base64_encode($contenu)); 
134               
135               
136         $from=$args['from'];
137$to="";
138
139     $message_texte=sprintf(
140        l10n('Sv_message_texte %s %s %s'),
141        format_date( date("Y-m-d H:i:s")),
142                $to,
143                $from
144        );     
145               
146 
147        $message_html =         '<img src="'.PHPWG_ROOT_PATH.'admin/template/goto/theme/roma/images/piwigo_logo_sombre_214x100.png" />';
148         ob_start();   
149 
150        echo str_replace("\n","<br />",$message_texte);
151       
152         $message_html .= ob_get_contents()."\n";
153         //ob_flush();
154        ob_end_clean();
155
156       $limite=$conf_mail['boundary_key'];   
157                $headers =   date("Y-m-d H:i:s") ."\n"; 
158
159  //=======================================================================================
160                $headers = "From: ".$args['from']."\n";
161                $headers.= "Reply-To: ".$args['from']."\n";
162                $nb_destinataires=0;
163$destinataire = $conf_mail['email_webmaster'];
164
165 
166                if (!empty($args['Cc']))
167                {$nb_destinataires += count($args['Cc']);
168                 $to= explode(',', $args['Cc']);
169                 $headers       .= get_strict_email_list($to) ;
170                   
171                }
172                if (!empty($args['Bcc']))
173                {  $nb_destinataires += count($args['Bcc']); 
174            $to = implode(',', $args['Bcc']);
175            $headers    .= 'Bcc :'.get_strict_email_list($to)."\n" ;
176                   
177                }
178
179  $headers.= 'Content-Type: multipart/alternative;'."\n";
180  $headers.= '  boundary="---='.$limite.'";'."\n";
181  $headers.= '  reply-type=original'."\n";
182  $headers.= 'MIME-Version: 1.0'."\n";
183  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
184
185  //Le message en texte simple pour les navigateurs qui n'acceptent pas le HTML
186    $texte = "This is a multi-part message in MIME format.\n"; 
187       
188        $texte .= "-----=".$limite."\n"; 
189        $texte .= "Ceci est un message est au format MIME.\n"; 
190        $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
191        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
192        $texte .= $message_texte ; 
193                $texte .= "\n\n"; 
194               
195                $texte .= "-----=".$limite."\n"; 
196        $texte .= 'Content-Type: text/html; charset="UTF-8"'."\n"; 
197        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
198        $texte .= $message_html; 
199        $texte .= "\n\n"; 
200         
201
202
203                $attachement = "-----=".$limite."\n"; 
204                $attachement .= "Content-Type: ".$typemime."; name=\"".$nom."\"\n"; 
205                $attachement .= "Content-Transfer-Encoding: base64\n"; 
206                $attachement .= "Content-Disposition: attachment; filename=\"".$nom."\"\n\n"; 
207                $attachement .= $piecejointe; 
208                $attachement .= "\n\n\n-----=".$limite."\n"; 
209
210
211  $ret=false;
212
213ob_start();
214
215    $ret= mail( $destinataire, $args['subject'], $texte.$attachement, $headers); 
216   $message =  ob_get_contents() ;
217        //ob_flush();
218   ob_end_clean();
219   if (($message)<>"") {
220   $erreur_message .=  $message ;
221   $infos_message =  "-------------------";
222   }
223
224    return  $ret;
225 
226}
227
228
229?>
Note: See TracBrowser for help on using the repository browser.