Ignore:
Timestamp:
Jan 20, 2013, 3:17:42 PM (11 years ago)
Author:
julien1311
Message:

[piwecard] add email improvements and stats in admin_management.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Piwecard/include/piwecard.class.php

    r20254 r20284  
    415415        //Send an email
    416416        function mail($email_infos) {
    417                 global $conf, $page, $lang_info;
     417                global $lang_info;
    418418                $template_mail = new Template(PIWECARD_MAIL_PATH.'template');
    419419                $smarty = $template_mail->smarty;
    420420               
    421                 $from = $email_infos['from_name']." <".$email_infos['from_email'].">";
     421                $from = '"'.$email_infos['from_name'].'" <'.$email_infos['from_email'].'>';
    422422                $subject = encode_mime_header(trim(preg_replace('#[\n\r]+#s', '', $email_infos['subject'])));
    423423                $boundary = '_----------='.md5(uniqid(mt_rand()));
     
    436436               
    437437                if (empty($email_infos['message']['html'])) {           //Text plain email
     438                        $headers .= 'Content-Type: text/plain; charset="'.get_pwg_charset().'"'."\n";
    438439                        $headers .= 'Content-Transfer-Encoding: 8bit'."\n";
    439                         $message .= $email_infos['message']['text'];
    440                         $smarty->assign(array(
    441                                                                         'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'],
    442                                                                         'GALLERY_URL' => get_absolute_root_url(),
    443                                                                         'MAIL' => get_webmaster_mail_address(),
    444                                                                 )
    445                         );
    446                         $message .= $smarty->fetch('mail_text.tpl');
    447                         $message = utf8_decode($message);
     440                        $message = $this->get_text_message($email_infos['message']['text'], $smarty);
    448441                } else {
    449442                        $headers .= 'MIME-Version: 1.0'."\n";
     
    453446                        $message .= 'Content-Type: text/plain; charset="'.get_pwg_charset().'"'."\n";
    454447                        $message .= 'Content-Transfer-Encoding: binary'."\n\n";
    455                         $message .= $email_infos['message']['text']."\n\n";
     448                        $message .= $this->get_text_message($email_infos['message']['text'], $smarty);
     449                        $message .= "\n\n";
    456450                        $message .= '--'.$boundary."\n";
    457451                        $message .= 'Content-Type: text/html; charset="'.get_pwg_charset().'"'."\n";
    458452                        $message .= 'Content-Transfer-Encoding: binary;'."\n\n";
    459                         $smarty->assign(array(
    460                                                                         'CONTENT_ENCODING' => get_pwg_charset(),
    461                                                                         'GALLERY_URL' => get_absolute_root_url(),
    462                                                                         'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'],
    463                                                                         'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
    464                                                                         'MAIL' => get_webmaster_mail_address(),
    465                                                                         'MESSAGE_HTML' => $email_infos['message']['html'],
    466                                                                 )
    467                         );
    468                         $message .= $smarty->fetch('mail_html.tpl');
     453                        $message .= $this->get_html_message($email_infos['message']['html'], $smarty);
    469454                        $message .= "\n\n";
    470455                        $message .= '--'.$boundary."--\n";
     
    473458                mail($email_infos['to'], $subject, $message, $headers);
    474459        }
     460       
     461        function get_text_message($message_text, $smarty) {
     462                global $page, $conf;
     463               
     464                $message = $message_text;
     465                $smarty->assign(array(
     466                                                                'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'],
     467                                                                'GALLERY_URL' => get_absolute_root_url(),
     468                                                                'MAIL' => get_webmaster_mail_address(),
     469                                                        )
     470                );
     471                $message .= $smarty->fetch('mail_text.tpl');
     472               
     473                return $message;
     474        }
     475       
     476        function get_html_message($message_html, $smarty) {
     477                global $page, $conf;
     478               
     479                $smarty->assign(array(
     480                                                                'CONTENT_ENCODING' => get_pwg_charset(),
     481                                                                'GALLERY_URL' => get_absolute_root_url(),
     482                                                                'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'],
     483                                                                'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
     484                                                                'MAIL' => get_webmaster_mail_address(),
     485                                                                'MESSAGE_HTML' => $message_html,
     486                                                        )
     487                );
     488                $message = $smarty->fetch('mail_html.tpl');
     489               
     490                return $message;
     491        }
    475492}
    476493?>
Note: See TracChangeset for help on using the changeset viewer.