当前位置: 首页>>代码示例>>PHP>>正文


PHP Validate::isTplName方法代码示例

本文整理汇总了PHP中Validate::isTplName方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::isTplName方法的具体用法?PHP Validate::isTplName怎么用?PHP Validate::isTplName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validate的用法示例。


在下文中一共展示了Validate::isTplName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Send

 /**
  * Send Email
  * 
  * @param int $id_lang Language of the email (to translate the template)
  * @param string $template Template: the name of template not be a var but a string !
  * @param string $subject
  * @param string $template_vars
  * @param string $to
  * @param string $to_name
  * @param string $from
  * @param string $from_name
  * @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
  * @param bool $modeSMTP
  * @param string $template_path
  * @param bool $die
  */
 public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null)
 {
     $theme_path = _PS_THEME_DIR_;
     // Get the path of theme by id_shop if exist
     if (is_numeric($id_shop) && $id_shop) {
         $shop = new Shop((int) $id_shop);
         $theme_name = $shop->getTheme();
         if (_THEME_NAME_ != $theme_name) {
             $theme_path = _PS_ROOT_DIR_ . '/themes/' . $theme_name . '/';
         }
     }
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = 'default';
     }
     // Sending an e-mail can be of vital importance for the merchant, when his password is lost for example, so we must not die but do our best to send the e-mail
     if (!isset($from) || !Validate::isEmail($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!Validate::isEmail($from)) {
         $from = null;
     }
     // $from_name is not that important, no need to die if it is not valid
     if (!isset($from_name) || !Validate::isMailName($from_name)) {
         $from_name = $configuration['PS_SHOP_NAME'];
     }
     if (!Validate::isMailName($from_name)) {
         $from_name = null;
     }
     // It would be difficult to send an e-mail if the e-mail is not valid, so this time we can die if there is a problem
     if (!is_array($to) && !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     if (!is_array($template_vars)) {
         $template_vars = array();
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($to_name) && !empty($to_name) && !Validate::isMailName($to_name)) {
         $to_name = null;
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     if (is_array($to) && isset($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = null;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid e-mail address'), $die);
                 return false;
             }
             if (is_array($to_name)) {
                 if ($to_name && is_array($to_name) && Validate::isGenericName($to_name[$key])) {
                     $to_name = $to_name[$key];
                 }
             }
             if ($to_name == null) {
                 $to_name = $addr;
             }
             /* Encode accentuated chars */
             $to_list->addTo($addr, '=?UTF-8?B?' . base64_encode($to_name) . '?=');
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         if ($to_name == null) {
             $to_name = $to;
         }
         $to = new Swift_Address($to, '=?UTF-8?B?' . base64_encode($to_name) . '?=');
     }
     try {
//.........这里部分代码省略.........
开发者ID:jicheng17,项目名称:vipinsg,代码行数:101,代码来源:Mail.php

示例2: Send

 public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_)
 {
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = "off";
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = "default";
     }
     if (!isset($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!isset($fromName)) {
         $fromName = $configuration['PS_SHOP_NAME'];
     }
     if (!empty($from) and !Validate::isEmail($from) or !empty($fromName) and !Validate::isMailName($fromName) or !is_array($to) and !Validate::isEmail($to) or !empty($toName) and !Validate::isMailName($toName) or !is_array($templateVars) or !Validate::isTplName($template) or !Validate::isMailSubject($subject)) {
         die(Tools::displayError('Error: mail parameters are corrupted'));
     }
     /* Construct multiple recipients list if needed */
     if (is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = NULL;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 die(Tools::displayError('Error: mail parameters are corrupted'));
             }
             if ($toName and is_array($toName) and Validate::isGenericName($toName[$key])) {
                 $to_name = $toName[$key];
             }
             $to_list->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, $toName);
     }
     try {
         /* Connect with the appropriate configuration */
         if (intval($configuration['PS_MAIL_METHOD']) == 2) {
             $connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl" ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['PS_MAIL_USER']) and !empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection);
         /* Get templates content */
         $iso = Language::getIsoById(intval($id_lang));
         if (!$iso) {
             die(Tools::displayError('Error - No iso code for email !'));
         }
         $template = $iso . '/' . $template;
         if (!file_exists($templatePath . $template . '.txt') or !file_exists($templatePath . $template . '.html')) {
             die(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.txt');
         }
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         $templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath . $template . '.txt'), NULL, 'utf-8'));
         include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
         global $_LANGMAIL;
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . ((is_array($_LANGMAIL) and key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject));
         $templateVars['{shop_logo}'] = file_exists(_PS_IMG_DIR_ . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo.jpg'))) : '';
         $templateVars['{shop_name}'] = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8');
         $templateVars['{shop_url}'] = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__;
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 2) {
             $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 1) {
             $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
         }
         if ($fileAttachment and isset($fileAttachment['content']) and isset($fileAttachment['name']) and isset($fileAttachment['mime'])) {
             $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
         $swift->disconnect();
         return $send;
     } catch (Swift_ConnectionException $e) {
         return false;
     }
 }
开发者ID:sealence,项目名称:local,代码行数:94,代码来源:Mail.php

示例3: Send

 /**
  * Send Email
  * 
  * @param int $id_lang Language of the email (to translate the template)
  * @param string $template Template: the name of template not be a var but a string !
  * @param string $subject
  * @param string $template_vars
  * @param string $to
  * @param string $to_name
  * @param string $from
  * @param string $from_name
  * @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
  * @param bool $modeSMTP
  * @param string $template_path
  * @param bool $die
  * @param string $bcc Bcc recipient
  */
 public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null)
 {
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_TYPE'), null, null, $id_shop);
     // Returns immediatly if emails are deactivated
     if ($configuration['PS_MAIL_METHOD'] == 3) {
         return true;
     }
     $theme_path = _PS_THEME_DIR_;
     // Get the path of theme by id_shop if exist
     if (is_numeric($id_shop) && $id_shop) {
         $shop = new Shop((int) $id_shop);
         $theme_name = $shop->getTheme();
         if (_THEME_NAME_ != $theme_name) {
             $theme_path = _PS_ROOT_DIR_ . '/themes/' . $theme_name . '/';
         }
     }
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = 'default';
     }
     // Sending an e-mail can be of vital importance for the merchant, when his password is lost for example, so we must not die but do our best to send the e-mail
     if (!isset($from) || !Validate::isEmail($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!Validate::isEmail($from)) {
         $from = null;
     }
     // $from_name is not that important, no need to die if it is not valid
     if (!isset($from_name) || !Validate::isMailName($from_name)) {
         $from_name = $configuration['PS_SHOP_NAME'];
     }
     if (!Validate::isMailName($from_name)) {
         $from_name = null;
     }
     // It would be difficult to send an e-mail if the e-mail is not valid, so this time we can die if there is a problem
     if (!is_array($to) && !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     if (!is_array($template_vars)) {
         $template_vars = array();
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($to_name) && !empty($to_name) && !Validate::isMailName($to_name)) {
         $to_name = null;
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     $to_list = new Swift_RecipientList();
     if (is_array($to) && isset($to)) {
         foreach ($to as $key => $addr) {
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid e-mail address'), $die);
                 return false;
             }
             if (is_array($to_name)) {
                 if ($to_name && is_array($to_name) && Validate::isGenericName($to_name[$key])) {
                     $to_name = $to_name[$key];
                 }
             }
             if ($to_name == null || $to_name == $addr) {
                 $to_name = '';
             } else {
                 if (function_exists('mb_encode_mimeheader')) {
                     $to_name = mb_encode_mimeheader($to_name, 'utf-8');
                 } else {
                     $to_name = self::mimeEncode($to_name);
                 }
             }
             $to_list->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
     } else {
//.........这里部分代码省略.........
开发者ID:dev-lav,项目名称:htdocs,代码行数:101,代码来源:Mail.php

示例4: submitTranslationsMails

 /**
  * This method is used to wright translation for mails.
  * This wrights subject translation files
  * (in root/mails/lang_choosen/lang.php or root/_PS_THEMES_DIR_/mails/lang_choosen/lang.php)
  * and mails files.
  */
 protected function submitTranslationsMails()
 {
     $arr_mail_content = array();
     $arr_mail_path = array();
     if (Tools::getValue('core_mail')) {
         $arr_mail_content['core_mail'] = Tools::getValue('core_mail');
         // Get path of directory for find a good path of translation file
         if ($this->theme_selected != self::DEFAULT_THEME_NAME) {
             $arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['override']['dir'];
         } else {
             $arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['dir'];
         }
     }
     if (Tools::getValue('module_mail')) {
         $arr_mail_content['module_mail'] = Tools::getValue('module_mail');
         // Get path of directory for find a good path of translation file
         if ($this->theme_selected != self::DEFAULT_THEME_NAME) {
             $arr_mail_path['module_mail'] = $this->translations_informations['modules']['override']['dir'] . '{module}/mails/' . $this->lang_selected->iso_code . '/';
         } else {
             $arr_mail_path['module_mail'] = $this->translations_informations['modules']['dir'] . '{module}/mails/' . $this->lang_selected->iso_code . '/';
         }
     }
     // Save each mail content
     foreach ($arr_mail_content as $group_name => $all_content) {
         foreach ($all_content as $type_content => $mails) {
             foreach ($mails as $mail_name => $content) {
                 $module_name = false;
                 $module_name_pipe_pos = stripos($mail_name, '|');
                 if ($module_name_pipe_pos) {
                     $module_name = substr($mail_name, 0, $module_name_pipe_pos);
                     if (!Validate::isModuleName($module_name)) {
                         throw new PrestaShopException(sprinf(Tools::displayError('Invalid module name "%s"'), $module_name));
                     }
                     $mail_name = substr($mail_name, $module_name_pipe_pos + 1);
                     if (!Validate::isTplName($mail_name)) {
                         throw new PrestaShopException(sprintf(Tools::displayError('Invalid mail name "%s"'), $mail_name));
                     }
                 }
                 if ($type_content == 'html') {
                     $content = Tools::htmlentitiesUTF8($content);
                     $content = htmlspecialchars_decode($content);
                     // replace correct end of line
                     $content = str_replace("\r\n", PHP_EOL, $content);
                     $title = '';
                     if (Tools::getValue('title_' . $group_name . '_' . $mail_name)) {
                         $title = Tools::getValue('title_' . $group_name . '_' . $mail_name);
                     }
                     $string_mail = $this->getMailPattern();
                     $content = str_replace(array('#title', '#content'), array($title, $content), $string_mail);
                     // Magic Quotes shall... not.. PASS!
                     if (_PS_MAGIC_QUOTES_GPC_) {
                         $content = stripslashes($content);
                     }
                 }
                 if (Validate::isCleanHTML($content)) {
                     $path = $arr_mail_path[$group_name];
                     if ($module_name) {
                         $path = str_replace('{module}', $module_name, $path);
                     }
                     file_put_contents($path . $mail_name . '.' . $type_content, $content);
                 } else {
                     throw new PrestaShopException(Tools::displayError('HTML e-mail templates cannot contain JavaScript code.'));
                 }
             }
         }
     }
     // Update subjects
     $array_subjects = array();
     if (($subjects = Tools::getValue('subject')) && is_array($subjects)) {
         $array_subjects['core_and_modules'] = array('translations' => array(), 'path' => $arr_mail_path['core_mail'] . 'lang.php');
         foreach ($subjects as $subject_translation) {
             $array_subjects['core_and_modules']['translations'] = array_merge($array_subjects['core_and_modules']['translations'], $subject_translation);
         }
     }
     if (!empty($array_subjects)) {
         foreach ($array_subjects as $infos) {
             $this->writeSubjectTranslationFile($infos['translations'], $infos['path']);
         }
     }
     if (Tools::isSubmit('submitTranslationsMailsAndStay')) {
         $this->redirect(true);
     } else {
         $this->redirect();
     }
 }
开发者ID:rrameshsat,项目名称:Prestashop,代码行数:91,代码来源:AdminTranslationsController.php

示例5: Send

 public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_, $die = false)
 {
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = 'default';
     }
     if (!isset($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!isset($fromName)) {
         $fromName = $configuration['PS_SHOP_NAME'];
     }
     if (!empty($from) and !Validate::isEmail($from)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "from" is corrupted'), $die);
         return false;
     }
     if (!empty($fromName) and !Validate::isMailName($fromName)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "fromName" is corrupted'), $die);
         return false;
     }
     if (!is_array($to) and !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     if (!is_array($templateVars)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "templateVars" is not an array'), $die);
         return false;
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($toName)) {
         if (!empty($toName) and !Validate::isMailName($toName)) {
             $toName = NULL;
         }
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     if (is_array($to) and isset($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = NULL;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid email address'), $die);
                 return false;
             }
             if (is_array($toName)) {
                 if ($toName and is_array($toName) and Validate::isGenericName($toName[$key])) {
                     $to_name = $toName[$key];
                 }
             }
             $to_list->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, $toName);
     }
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['PS_MAIL_METHOD'] == 2) {
             if (empty($configuration['PS_MAIL_SERVER']) or empty($configuration['PS_MAIL_SMTP_PORT'])) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
                 return false;
             }
             $connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl" ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['PS_MAIL_USER'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
             }
             if (!empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN'));
         /* Get templates content */
         $iso = Language::getIsoById((int) $id_lang);
         if (!$iso) {
             Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
             return false;
         }
//.........这里部分代码省略.........
开发者ID:ricardo-rdfs,项目名称:Portal-BIP,代码行数:101,代码来源:Mail.php

示例6: getThemeOverride

 public function getThemeOverride($template_file)
 {
     if (!Validate::isTplName($template_file)) {
         throw new Exception(Tools::displayError('Invalid template name'));
     }
     $path = $this->getCurrentThemeDir();
     if ($path && file_exists($path . $template_file . '.tpl')) {
         return $path . $template_file . '.tpl';
     }
     return false;
 }
开发者ID:pomdev,项目名称:modules-1.6.0.9,代码行数:11,代码来源:eu_legal.php

示例7: Send

 /**
  * Send Email
  *
  * @param int $id_lang Language ID of the email (to translate the template)
  * @param string $template Template: the name of template not be a var but a string !
  * @param string $subject Subject of the email
  * @param string $template_vars Template variables for the email
  * @param string $to To email
  * @param string $to_name To name
  * @param string $from From email
  * @param string $from_name To email
  * @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
  * @param bool $mode_smtp SMTP mode (deprecated)
  * @param string $template_path Template path
  * @param bool $die Die after error
  * @param string $bcc Bcc recipient
  * @return bool|int Whether sending was successful. If not at all, false, otherwise amount of recipients succeeded.
  */
 public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null)
 {
     if (!$id_shop) {
         $id_shop = Context::getContext()->shop->id;
     }
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_TYPE'), null, null, $id_shop);
     // Returns immediatly if emails are deactivated
     if ($configuration['PS_MAIL_METHOD'] == 3) {
         return true;
     }
     $theme_path = _PS_THEME_DIR_;
     // Get the path of theme by id_shop if exist
     if (is_numeric($id_shop) && $id_shop) {
         $shop = new Shop((int) $id_shop);
         $theme_name = $shop->getTheme();
         if (_THEME_NAME_ != $theme_name) {
             $theme_path = _PS_ROOT_DIR_ . '/themes/' . $theme_name . '/';
         }
     }
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION']) || Tools::strtolower($configuration['PS_MAIL_SMTP_ENCRYPTION']) === 'off') {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = false;
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = 'default';
     }
     // Sending an e-mail can be of vital importance for the merchant, when his password is lost for example, so we must not die but do our best to send the e-mail
     if (!isset($from) || !Validate::isEmail($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!Validate::isEmail($from)) {
         $from = null;
     }
     // $from_name is not that important, no need to die if it is not valid
     if (!isset($from_name) || !Validate::isMailName($from_name)) {
         $from_name = $configuration['PS_SHOP_NAME'];
     }
     if (!Validate::isMailName($from_name)) {
         $from_name = null;
     }
     // It would be difficult to send an e-mail if the e-mail is not valid, so this time we can die if there is a problem
     if (!is_array($to) && !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     // if bcc is not null, make sure it's a vaild e-mail
     if (!is_null($bcc) && !is_array($bcc) && !Validate::isEmail($bcc)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "bcc" is corrupted'), $die);
         $bcc = null;
     }
     if (!is_array($template_vars)) {
         $template_vars = array();
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($to_name) && !empty($to_name) && !Validate::isMailName($to_name)) {
         $to_name = null;
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     $message = Swift_Message::newInstance();
     if (is_array($to) && isset($to)) {
         foreach ($to as $key => $addr) {
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid e-mail address'), $die);
                 return false;
             }
             if (is_array($to_name) && $to_name && is_array($to_name) && Validate::isGenericName($to_name[$key])) {
                 $to_name = $to_name[$key];
             }
             $to_name = $to_name == null || $to_name == $addr ? '' : self::mimeEncode($to_name);
             $message->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
     } else {
         /* Simple recipient, one address */
//.........这里部分代码省略.........
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:101,代码来源:Mail.php

示例8: Send

 public static function Send($template, $subject, $templateVars, $to, $toName = null, $from = null, $fromName = null, $fileAttachment = null, $modeSMTP = null, $templatePath = null, $die = false)
 {
     $configuration = Configuration::getMultiple(array('TM_SHOP_EMAIL', 'TM_MAIL_METHOD', 'TM_MAIL_SERVER', 'TM_MAIL_USER', 'TM_MAIL_PASSWD', 'TM_SHOP_NAME', 'TM_MAIL_SMTP_ENCRYPTION', 'TM_MAIL_SMTP_PORT', 'TM_MAIL_METHOD'));
     if (!isset($configuration['TM_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['TM_MAIL_SMTP_ENCRYPTION'] = 'off';
     }
     if (!isset($configuration['TM_MAIL_SMTP_PORT'])) {
         $configuration['TM_MAIL_SMTP_PORT'] = 'default';
     }
     if (!isset($from)) {
         $from = $configuration['TM_SHOP_EMAIL'];
     }
     if (!isset($fromName)) {
         $fromName = $configuration['TM_SHOP_NAME'];
     }
     if (!empty($from) && !Validate::isEmail($from)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "from" is corrupted'), $die);
         return false;
     }
     if (!empty($fromName) && !Validate::isMailName($fromName)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "fromName" is corrupted'), $die);
         return false;
     }
     if (!is_array($to) && !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     if (!is_array($templateVars)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "templateVars" is not an array'), $die);
         return false;
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($toName)) {
         if (!empty($toName) && !Validate::isMailName($toName)) {
             $toName = null;
         }
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     if (isset($to) && is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = null;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid email address'), $die);
                 return false;
             }
             if (is_array($toName)) {
                 if ($toName && is_array($toName) && Validate::isGenericName($toName[$key])) {
                     $to_name = $toName[$key];
                 }
             }
             $to_list->addTo($addr, base64_encode($to_name));
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, base64_encode($toName));
     }
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['TM_MAIL_METHOD'] == 2) {
             if (empty($configuration['TM_MAIL_SERVER']) || empty($configuration['TM_MAIL_SMTP_PORT'])) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
                 return false;
             }
             $connection = new Swift_Connection_SMTP($configuration['TM_MAIL_SERVER'], $configuration['TM_MAIL_SMTP_PORT'], $configuration['TM_MAIL_SMTP_ENCRYPTION'] == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : ($configuration['TM_MAIL_SMTP_ENCRYPTION'] == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(20);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['TM_MAIL_USER'])) {
                 $connection->setUsername($configuration['TM_MAIL_USER']);
             }
             if (!empty($configuration['TM_MAIL_PASSWD'])) {
                 $connection->setPassword($configuration['TM_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection, Configuration::get('TM_MAIL_DOMAIN'));
         // get templatePath
         $templatePath = _TM_THEMES_DIR . 'mails/';
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         /* Create mail && attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('TM_SHOP_NAME') . '] ' . $subject);
         $templateVars['{shop_logo}'] = file_exists(_TM_IMG_DIR . 'logo_mail.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_TM_IMG_DIR . 'logo_mail.jpg'))) : (file_exists(_TM_IMG_DIR . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_TM_IMG_DIR . 'logo.jpg'))) : '');
//.........这里部分代码省略.........
开发者ID:yiuked,项目名称:tmcart,代码行数:101,代码来源:Mail.php

示例9: submitTranslationsMails

 /**
  * This method is used to wright translation for mails.
  * This wrights subject translation files 
  * (in root/mails/lang_choosen/lang.php or root/_PS_THEMES_DIR_/mails/lang_choosen/lang.php)
  * and mails files. 
  *
  * @param int $id_lang
  */
 protected function submitTranslationsMails($id_lang)
 {
     global $currentIndex;
     $obj_lang = new Language($id_lang);
     $params_redirect = Tools::isSubmit('submitTranslationsMailsAndStay') ? '&lang=' . Tools::getValue('lang') . '&type=' . Tools::getValue('type') : '';
     $arr_mail_content = array();
     $arr_mail_path = array();
     if (Tools::getValue('core_mail')) {
         $arr_mail_content['core_mail'] = Tools::getValue('core_mail');
         $arr_mail_path['core_mail'] = _PS_MAIL_DIR_ . $obj_lang->iso_code . '/';
     }
     if (Tools::getValue('module_mail')) {
         $arr_mail_content['module_mail'] = Tools::getValue('module_mail');
         $arr_mail_path['module_mail'] = _PS_MODULE_DIR_ . '{module}' . '/mails/' . $obj_lang->iso_code . '/';
     }
     if (Tools::getValue('theme_mail')) {
         $arr_mail_content['theme_mail'] = Tools::getValue('theme_mail');
         $arr_mail_path['theme_mail'] = $this->theme_dir . 'mails/' . $obj_lang->iso_code . '/';
     }
     if (Tools::getValue('theme_module_mail')) {
         $arr_mail_content['theme_module_mail'] = Tools::getValue('theme_module_mail');
         $arr_mail_path['theme_module_mail'] = $this->theme_dir . 'modules/{module}' . '/mails/' . $obj_lang->iso_code . '/';
     }
     // Save each mail content
     foreach ($arr_mail_content as $group_name => $all_content) {
         foreach ($all_content as $type_content => $mails) {
             if (!in_array($type_content, array('txt', 'html'))) {
                 die(Tools::displayError());
             }
             foreach ($mails as $mail_name => $content) {
                 $module_name = false;
                 $module_name_pipe_pos = stripos($mail_name, '|');
                 if ($module_name_pipe_pos) {
                     $module_name = substr($mail_name, 0, $module_name_pipe_pos);
                     if (!Validate::isModuleName($module_name)) {
                         die(Tools::displayError());
                     }
                     $mail_name = substr($mail_name, $module_name_pipe_pos + 1);
                     if (!Validate::isTplName($mail_name)) {
                         die(Tools::displayError());
                     }
                 }
                 if ($type_content == 'html') {
                     $content = Tools::htmlentitiesUTF8($content);
                     $content = htmlspecialchars_decode($content);
                     // replace correct end of line
                     $content = str_replace("\r\n", PHP_EOL, $content);
                     $title = '';
                     if (Tools::getValue('title_' . $group_name . '_' . $mail_name)) {
                         $title = Tools::getValue('title_' . $group_name . '_' . $mail_name);
                     }
                     $string_mail = $this->getMailPattern();
                     $content = str_replace(array('#title', '#content'), array($title, $content), $string_mail);
                     // Magic Quotes shall... not.. PASS!
                     if (_PS_MAGIC_QUOTES_GPC_) {
                         $content = stripslashes($content);
                     }
                 }
                 if (Validate::isCleanHTML($content)) {
                     $path = $arr_mail_path[$group_name];
                     if ($module_name) {
                         $path = str_replace('{module}', $module_name, $path);
                     }
                     file_put_contents($path . $mail_name . '.' . $type_content, $content);
                     chmod($path . $mail_name . '.' . $type_content, 0777);
                 } else {
                     $this->_errors[] = Tools::displayError('HTML e-mail templates cannot contain JavaScript code.');
                 }
             }
         }
     }
     // Update subjects
     $array_subjects = array();
     if ($subjects = Tools::getValue('subject') and is_array($subjects)) {
         $array_subjects['core_and_modules'] = array('translations' => array(), 'path' => $arr_mail_path['core_mail'] . 'lang.php');
         if (isset($arr_mail_path['theme_mail'])) {
             $array_subjects['themes_and_modules'] = array('translations' => array(), 'path' => $arr_mail_path['theme_mail'] . 'lang.php');
         }
         foreach ($subjects as $group => $subject_translation) {
             if ($group == 'core_mail' || $group == 'module_mail') {
                 $array_subjects['core_and_modules']['translations'] = array_merge($array_subjects['core_and_modules']['translations'], $subject_translation);
             } elseif (isset($array_subjects['themes_and_modules']) && ($group == 'theme_mail' || $group == 'theme_module_mail')) {
                 $array_subjects['themes_and_modules']['translations'] = array_merge($array_subjects['themes_and_modules']['translations'], $subject_translation);
             }
         }
     }
     if (!empty($array_subjects)) {
         foreach ($array_subjects as $type => $infos) {
             $this->writeSubjectTranslationFile($infos['translations'], $infos['path']);
         }
     }
     if (count($this->_errors) == 0) {
//.........这里部分代码省略.........
开发者ID:Evil1991,项目名称:PrestaShop-1.4,代码行数:101,代码来源:AdminTranslations.php


注:本文中的Validate::isTplName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。