function send($page_url = false) { global $tpl, $opt; if (!$this->template_exists($this->name . '.tpl')) { $tpl->error(ERROR_MAIL_TEMPLATE_NOT_FOUND); } $this->assign('template', $this->name); if (!$this->recipient_locale) { $this->recipient_locale = $opt['template']['locale']; } $optn['mail']['contact'] = $opt['mail']['contact']; $optn['page']['absolute_url'] = $page_url ? $page_url : $opt['page']['absolute_url']; $optn['page']['sitename'] = $opt['page']['sitename']; $optn['format'] = $opt['locale'][$this->recipient_locale]['format']; $this->assign('opt', $optn); $this->assign('to', $this->to); $this->assign('from', $this->from); $this->assign('subject', $this->subject); // This is nasty, but as there is only a global translation system // (based on gettext) and there are no precompiled, language-dependend email // templates available, we must temporarily change the locale according to // the recipient's locale. If some error occurs while running fetch(), // the error message may be displayed in the recipient's language. $sender_locale = $opt['template']['locale']; if ($this->recipient_locale != $sender_locale) { $opt['template']['locale'] = $this->recipient_locale; set_php_locale(); } $body = $this->fetch($this->main_template . '.tpl', '', $this->get_compile_id()); if ($this->recipient_locale != $sender_locale) { $opt['template']['locale'] = $sender_locale; set_php_locale(); } // check if the target domain exists if the domain does not // exist, the mail is sent to the own domain (?!) $domain = mail::getToMailDomain($this->to); if (mail::is_existent_maildomain($domain) == false) { return false; } $aAddHeaders = array(); $aAddHeaders[] = 'From: "' . $this->from . '" <' . $this->from . '>'; if ($this->replyTo !== null) { $aAddHeaders[] = 'Reply-To: ' . $this->replyTo; } if ($this->returnPath !== null) { $aAddHeaders[] = 'Return-Path: ' . $this->returnPath; } $mailheaders = implode("\n", array_merge($aAddHeaders, $this->headers)); return mb_send_mail($this->to, $opt['mail']['subject'] . $this->subject, $body, $mailheaders); }
function load_gettext() { global $cookie, $opt, $rootpath, $locale; $locale = $cookie->get('locale'); if (!isset($opt['locale'][$locale])) { $locale = $opt['template']['default']['locale']; } $opt['template']['locale'] = $locale; bindtextdomain('messages', $rootpath . '/cache2/translate'); set_php_locale(); textdomain('messages'); }
function set_language() { global $opt, $cookie; $savelocale = true; if (isset($_REQUEST['locale'])) { $opt['template']['locale'] = strtoupper($_REQUEST['locale']); } elseif (isset($_REQUEST['templocale'])) { $opt['template']['locale'] = strtoupper($_REQUEST['templocale']); $savelocale = false; } else { $opt['template']['locale'] = strtoupper($cookie->get('locale', $opt['template']['default']['locale'])); } if (isset($opt['template']['locale']) && $opt['template']['locale'] != '') { if (strpos($opt['template']['locale'], '.') !== false || strpos($opt['template']['locale'], '/') !== false) { $opt['template']['locale'] = $opt['template']['default']['locale']; } if (!isset($opt['locale'][$opt['template']['locale']])) { $opt['template']['locale'] = $opt['template']['default']['locale']; } } else { $opt['template']['locale'] = $opt['template']['default']['locale']; } if ($savelocale) { $cookie->set('locale', $opt['template']['locale'], $opt['template']['default']['locale']); } bindtextdomain('messages', $opt['rootpath'] . 'cache2/translate'); set_php_locale(); textdomain('messages'); }
function precompileTemplateWithLanguage($sTemplate, $sLanguage) { global $opt, $translate; // cheating a little bit $opt['template']['locale'] = $sLanguage; set_php_locale(); if ($translate->t('INTERNAL_LANG', 'all', 'OcSmarty.class.php', '') != $sLanguage) { die("setlocale() failed to set language to " . $sLanguage . ". Is the translation of INTERNAL_LANG correct?\n"); } $preTemplate = new OcSmarty(); $preTemplate->name = $sTemplate; $preTemplate->compile($sTemplate . '.tpl', $preTemplate->get_compile_id()); }