protected function deleteImage($image)
 {
     $file_name = $this->uploads_path . $image;
     if (realpath(dirname($file_name)) != realpath($this->uploads_path)) {
         Tools::dieOrLog(sprintf('Could not find upload directory'));
     }
     if ($image != '' && is_file($file_name) && !strpos($file_name, 'banner-img') && !strpos($file_name, 'bg-theme') && !strpos($file_name, 'footer-bg')) {
         unlink($file_name);
     }
 }
Example #2
0
 /**
  * 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 {
         /* Connect with the appropriate configuration */
         if ($configuration['PS_MAIL_METHOD'] == 2) {
             if (empty($configuration['PS_MAIL_SERVER']) || 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;
         }
         $template = $iso . '/' . $template;
         $module_name = false;
         $override_mail = false;
         // get templatePath
         if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', $template_path) && preg_match('#modules/([a-z0-9_-]+)/#ui', $template_path, $res)) {
             $module_name = $res[1];
         }
         if ($module_name !== false && (file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.txt') || file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.html'))) {
             $template_path = $theme_path . 'modules/' . $module_name . '/mails/';
         } else {
             if (file_exists($theme_path . 'mails/' . $template . '.txt') || file_exists($theme_path . 'mails/' . $template . '.html')) {
                 $template_path = $theme_path . 'mails/';
                 $override_mail = true;
             } else {
                 if (!file_exists($template_path . $template . '.txt') || !file_exists($template_path . $template . '.html')) {
                     Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.txt', $die);
                     return false;
                 }
             }
         }
         $template_html = file_get_contents($template_path . $template . '.html');
         $template_txt = strip_tags(html_entity_decode(file_get_contents($template_path . $template . '.txt'), null, 'utf-8'));
         if ($override_mail && file_exists($template_path . $iso . '/lang.php')) {
             include_once $template_path . $iso . '/lang.php';
         } else {
             if ($module_name && file_exists($template_path . $iso . '/lang.php')) {
                 include_once $theme_path . 'mails/' . $iso . '/lang.php';
             } else {
                 include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
             }
         }
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . $subject);
         $message->headers->setEncoding('Q');
         if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL'))) {
             $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL'))));
         } else {
             if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) {
                 $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . Configuration::get('PS_LOGO'))));
             } else {
                 $template_vars['{shop_logo}'] = '';
             }
         }
         $template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
         $template_vars['{shop_url}'] = Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'index.php';
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $template_vars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT) {
             $message->attach(new Swift_Message_Part($template_txt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) {
             $message->attach(new Swift_Message_Part($template_html, 'text/html', '8bit', 'utf-8'));
         }
         if ($file_attachment && !empty($file_attachment)) {
             // Multiple attachments?
             if (!is_array(current($file_attachment))) {
                 $file_attachment = array($file_attachment);
             }
             foreach ($file_attachment as $attachment) {
                 if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) {
                     $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime']));
                 }
             }
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $from_name));
         $swift->disconnect();
         return $send;
     } catch (Swift_Exception $e) {
         return false;
     }
 }
Example #3
0
}
$tabAccess = Profile::getProfileAccess(Context::getContext()->employee->id_profile, Tab::getIdFromClassName('AdminBackup'));
if ($tabAccess['view'] !== '1') {
    die(Tools::displayError('You do not have permission to view this.'));
}
$backupdir = realpath(PrestaShopBackup::getBackupPath());
if ($backupdir === false) {
    die(Tools::displayError('There is no "/backup" directory.'));
}
if (!($backupfile = Tools::getValue('filename'))) {
    die(Tools::displayError('No file has been specified.'));
}
// Check the realpath so we can validate the backup file is under the backup directory
$backupfile = realpath($backupdir . DIRECTORY_SEPARATOR . $backupfile);
if ($backupfile === false or strncmp($backupdir, $backupfile, strlen($backupdir)) != 0) {
    die(Tools::dieOrLog('The backup file does not exist.'));
}
if (substr($backupfile, -4) == '.bz2') {
    $contentType = 'application/x-bzip2';
} elseif (substr($backupfile, -3) == '.gz') {
    $contentType = 'application/x-gzip';
} else {
    $contentType = 'text/x-sql';
}
$fp = @fopen($backupfile, 'r');
if ($fp === false) {
    die(Tools::displayError('Unable to open backup file(s).') . ' "' . addslashes($backupfile) . '"');
}
// Add the correct headers, this forces the file is saved
header('Content-Type: ' . $contentType);
header('Content-Disposition: attachment; filename="' . Tools::getValue('filename') . '"');
 public function copyMailFilesForAllLanguages()
 {
     $current_theme = Tools::safeOutput($this->context->theme->name);
     $languages = Language::getLanguages();
     foreach ($languages as $key => $lang) {
         $dir_to_copy_iso = array();
         $files_to_copy_iso = array();
         $current_iso_code = $lang['iso_code'];
         $dir_to_copy_iso[] = _PS_MAIL_DIR_ . $current_iso_code . '/';
         $modules_has_mails = $this->getModulesHasMails(true);
         foreach ($modules_has_mails as $module_name => $module_path) {
             if ($pos = strpos($module_path, '/modules')) {
                 $dir_to_copy_iso[] = _PS_ROOT_DIR_ . substr($module_path, $pos) . 'mails/' . $current_iso_code . '/';
             }
         }
         foreach ($dir_to_copy_iso as $dir) {
             foreach (scandir($dir) as $file) {
                 if (!in_array($file, self::$ignore_folder)) {
                     $files_to_copy_iso[] = array("from" => $dir . $file, "to" => str_replace(_PS_ROOT_DIR_, _PS_ROOT_DIR_ . '/themes/' . $current_theme, $dir) . $file);
                 }
             }
         }
         foreach ($files_to_copy_iso as $file) {
             if (!file_exists($file['to'])) {
                 $content = file_get_contents($file['from']);
                 $stack = array();
                 $folder = dirname($file['to']);
                 while (!is_dir($folder)) {
                     array_push($stack, $folder);
                     $folder = dirname($folder);
                 }
                 while ($folder = array_pop($stack)) {
                     mkdir($folder);
                 }
                 $success = file_put_contents($file['to'], $content);
                 if ($success === false) {
                     Tools::dieOrLog(sprintf("%s cannot be copied to %s", $file['from'], $file['to']), false);
                 }
             }
         }
     }
     return true;
 }
Example #5
0
 /**
  * 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 {
         /* Simple recipient, one address */
         $to_plugin = $to;
         if ($to_name == null || $to_name == $to) {
             $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($to, $to_name);
     }
     if (isset($bcc)) {
         $to_list->addBcc($bcc);
     }
     $to = $to_list;
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['PS_MAIL_METHOD'] == 2) {
             if (empty($configuration['PS_MAIL_SERVER']) || 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', null, null, $id_shop));
         /* Get templates content */
         $iso = Language::getIsoById((int) $id_lang);
         if (!$iso) {
             Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
             return false;
         }
         $template = $iso . '/' . $template;
         $module_name = false;
         $override_mail = false;
         // get templatePath
         if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', str_replace(DIRECTORY_SEPARATOR, '/', $template_path)) && preg_match('#modules/([a-z0-9_-]+)/#ui', str_replace(DIRECTORY_SEPARATOR, '/', $template_path), $res)) {
             $module_name = $res[1];
         }
         if ($module_name !== false && (file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.txt') || file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.html'))) {
             $template_path = $theme_path . 'modules/' . $module_name . '/mails/';
         } elseif (file_exists($theme_path . 'mails/' . $template . '.txt') || file_exists($theme_path . 'mails/' . $template . '.html')) {
             $template_path = $theme_path . 'mails/';
             $override_mail = true;
         }
         if (!file_exists($template_path . $template . '.txt') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT)) {
             Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.txt', $die);
             return false;
         } else {
             if (!file_exists($template_path . $template . '.html') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML)) {
                 Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.html', $die);
                 return false;
             }
         }
         $template_html = file_get_contents($template_path . $template . '.html');
         $template_txt = strip_tags(html_entity_decode(file_get_contents($template_path . $template . '.txt'), null, 'utf-8'));
         if ($override_mail && file_exists($template_path . $iso . '/lang.php')) {
             include_once $template_path . $iso . '/lang.php';
         } else {
             if ($module_name && file_exists($theme_path . 'mails/' . $iso . '/lang.php')) {
                 include_once $theme_path . 'mails/' . $iso . '/lang.php';
             } else {
                 if (file_exists(_PS_MAIL_DIR_ . $iso . '/lang.php')) {
                     include_once _PS_MAIL_DIR_ . $iso . '/lang.php';
                 } else {
                     Tools::dieOrLog(Tools::displayError('Error - The lang file is missing for :') . ' ' . $iso, $die);
                     return false;
                 }
             }
         }
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME', null, null, $id_shop) . '] ' . $subject);
         $message->setCharset('utf-8');
         /* Set Message-ID - getmypid() is blocked on some hosting */
         $message->setId(Mail::generateId());
         $message->headers->setEncoding('Q');
         if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop))) {
             $logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop);
         } else {
             if (file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop))) {
                 $logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop);
             } else {
                 $template_vars['{shop_logo}'] = '';
             }
         }
         ShopUrl::cacheMainDomainForShop((int) $id_shop);
         /* don't attach the logo as */
         if (isset($logo)) {
             $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo)));
         }
         if (Context::getContext()->link instanceof Link === false) {
             Context::getContext()->link = new Link();
         }
         $template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME', null, null, $id_shop));
         $template_vars['{shop_url}'] = Context::getContext()->link->getPageLink('index', true, Context::getContext()->language->id);
         $template_vars['{my_account_url}'] = Context::getContext()->link->getPageLink('my-account', true, Context::getContext()->language->id);
         $template_vars['{guest_tracking_url}'] = Context::getContext()->link->getPageLink('guest-tracking', true, Context::getContext()->language->id);
         $template_vars['{history_url}'] = Context::getContext()->link->getPageLink('history', true, Context::getContext()->language->id);
         $template_vars['{color}'] = Tools::safeOutput(Configuration::get('PS_MAIL_COLOR', null, null, $id_shop));
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $template_vars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT) {
             $message->attach(new Swift_Message_Part($template_txt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) {
             $message->attach(new Swift_Message_Part($template_html, 'text/html', '8bit', 'utf-8'));
         }
         if ($file_attachment && !empty($file_attachment)) {
             // Multiple attachments?
             if (!is_array(current($file_attachment))) {
                 $file_attachment = array($file_attachment);
             }
             foreach ($file_attachment as $attachment) {
                 if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) {
                     $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime']));
                 }
             }
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $from_name));
         $swift->disconnect();
         ShopUrl::resetMainDomainCache();
         return $send;
     } catch (Swift_Exception $e) {
         return false;
     }
 }
 function hookLeftColumn($params)
 {
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = (int) Configuration::get('RSS_FEED_NBR');
     $cacheId = $this->getCacheId($this->name . '-' . date("YmdH"));
     if (!$this->isCached('blockrss.tpl', $cacheId)) {
         // Getting data
         $rss_links = array();
         if ($url && ($contents = Tools::file_get_contents($url))) {
             try {
                 if (@($src = new XML_Feed_Parser($contents))) {
                     for ($i = 0; $i < ($nb ? $nb : 5); $i++) {
                         if (@($item = $src->getEntryByOffset($i))) {
                             $xmlValues = array();
                             foreach (self::$xmlFields as $xmlField) {
                                 $xmlValues[$xmlField] = $item->__get($xmlField);
                             }
                             $xmlValues['enclosure'] = $item->getEnclosure();
                             // First image
                             if (isset($xmlValues['content']) && $xmlValues['content']) {
                                 preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/', $xmlValues['content'], $image);
                                 if (array_key_exists(1, $image) && $image[1]) {
                                     // Try if distant image exist : timeout 0.3s
                                     $context = stream_context_create(array('http' => array('timeout' => 0.3)));
                                     if (file_get_contents($image[1], false, $context, -1, 1) !== false) {
                                         $xmlValues['image'] = $image[1];
                                     }
                                 }
                             }
                             // Compatibility
                             $xmlValues['url'] = $xmlValues['link'];
                             $rss_links[] = $xmlValues;
                         }
                     }
                 }
             } catch (XML_Feed_Parser_Exception $e) {
                 Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false);
             }
         }
         // Display smarty
         $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links));
     }
     return $this->display(__FILE__, 'blockrss.tpl', $cacheId);
 }
Example #7
0
 function hookLeftColumn($params)
 {
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = (int) Configuration::get('RSS_FEED_NBR');
     // Getting data
     $rss_links = array();
     if ($url && ($contents = @file_get_contents($url))) {
         try {
             if (@($src = new XML_Feed_Parser($contents))) {
                 for ($i = 0; $i < ($nb ? $nb : 5); $i++) {
                     if (@($item = $src->getEntryByOffset($i))) {
                         $rss_links[] = array('title' => $item->title, 'url' => $item->link);
                     }
                 }
             }
         } catch (XML_Feed_Parser_Exception $e) {
             Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false);
         }
     }
     // Display smarty
     $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links));
     return $this->display(__FILE__, 'blockrss.tpl');
 }
Example #8
0
<?php

/**
 * Title   : Conekta Card Payment Gateway for Prestashop
 * Author  : Conekta.io
 * Url     : https://www.conekta.io/es/docs/plugins/prestashop.
 *
 *  @author Conekta <*****@*****.**>
 *  @copyright  2012-2016 Conekta
 *  @version  v1.2.0
 *  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
include dirname(__FILE__) . '/../../config/config.inc.php';
include dirname(__FILE__) . '/../../init.php';
include dirname(__FILE__) . '/conektaprestashop.php';
/* Todo: extend for subscriptions and meses sin intereses */
/* Check token */
$conekta = new ConektaPrestashop();
$conektaToken = Tools::getValue('conektaToken');
$type = Tools::getValue('type');
$monthly_installments = Tools::getValue('monthly_installments');
/* Check that module is active */
if ($conekta->active) {
    $conekta->processPayment($conektaToken, $type, $monthly_installments);
} else {
    Tools::dieOrLog('Token required, please check for any Javascript errors on the payment page.', true);
}
Example #9
0
 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;
         }
         $template = $iso . '/' . $template;
         $moduleName = false;
         $overrideMail = false;
         // get templatePath
         if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', $templatePath) and preg_match('#modules/([a-z0-9_-]+)/#ui', $templatePath, $res)) {
             $moduleName = $res[1];
         }
         if ($moduleName !== false and (file_exists(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/' . $template . '.txt') or file_exists(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/' . $template . '.html'))) {
             $templatePath = _PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/';
         } elseif (file_exists(_PS_THEME_DIR_ . 'mails/' . $template . '.txt') or file_exists(_PS_THEME_DIR_ . 'mails/' . $template . '.html')) {
             $templatePath = _PS_THEME_DIR_ . 'mails/';
             $overrideMail = true;
         } elseif (!file_exists($templatePath . $template . '.txt') or !file_exists($templatePath . $template . '.html')) {
             Tools::dieOrLog(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.txt', $die);
             return false;
         }
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         $templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath . $template . '.txt'), NULL, 'utf-8'));
         if ($overrideMail and file_exists($templatePath . $iso . '/lang.php')) {
             include_once $templatePath . $iso . '/lang.php';
         } elseif ($moduleName and file_exists($templatePath . $iso . '/lang.php')) {
             include_once _PS_THEME_DIR_ . 'mails/' . $iso . '/lang.php';
         } else {
             include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
         }
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . $subject);
         $templateVars['{shop_logo}'] = file_exists(_PS_IMG_DIR_ . 'logo_mail.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo_mail.jpg'))) : (file_exists(_PS_IMG_DIR_ . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo.jpg'))) : '');
         $templateVars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
         $templateVars['{shop_url}'] = Tools::getShopDomain(true, true) . __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;
     }
 }
Example #10
0
 /**
  * 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 */
         $to_plugin = $to;
         $to_name = $to_name == null || $to_name == $to ? '' : self::mimeEncode($to_name);
         $message->addTo($to, $to_name);
     }
     if (isset($bcc)) {
         $message->addBcc($bcc);
     }
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['PS_MAIL_METHOD'] == 2) {
             if (empty($configuration['PS_MAIL_SERVER']) || empty($configuration['PS_MAIL_SMTP_PORT'])) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
                 return false;
             }
             $connection = Swift_SmtpTransport::newInstance($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'])->setUsername($configuration['PS_MAIL_USER'])->setPassword($configuration['PS_MAIL_PASSWD']);
         } else {
             $connection = Swift_MailTransport::newInstance();
         }
         if (!$connection) {
             return false;
         }
         $swift = Swift_Mailer::newInstance($connection);
         /* Get templates content */
         $iso = Language::getIsoById((int) $id_lang);
         if (!$iso) {
             Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
             return false;
         }
         $iso_template = $iso . '/' . $template;
         $module_name = false;
         $override_mail = false;
         // get templatePath
         if (preg_match('#' . $shop->physical_uri . 'modules/#', str_replace(DIRECTORY_SEPARATOR, '/', $template_path)) && preg_match('#modules/([a-z0-9_-]+)/#ui', str_replace(DIRECTORY_SEPARATOR, '/', $template_path), $res)) {
             $module_name = $res[1];
         }
         if ($module_name !== false && (file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $iso_template . '.txt') || file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $iso_template . '.html'))) {
             $template_path = $theme_path . 'modules/' . $module_name . '/mails/';
         } elseif (file_exists($theme_path . 'mails/' . $iso_template . '.txt') || file_exists($theme_path . 'mails/' . $iso_template . '.html')) {
             $template_path = $theme_path . 'mails/';
             $override_mail = true;
         }
         if (!file_exists($template_path . $iso_template . '.txt') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT)) {
             Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $iso_template . '.txt', $die);
             return false;
         } elseif (!file_exists($template_path . $iso_template . '.html') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML)) {
             Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $iso_template . '.html', $die);
             return false;
         }
         $template_html = '';
         $template_txt = '';
         Hook::exec('actionEmailAddBeforeContent', array('template' => $template, 'template_html' => &$template_html, 'template_txt' => &$template_txt, 'id_lang' => (int) $id_lang), null, true);
         $template_html .= Tools::file_get_contents($template_path . $iso_template . '.html');
         $template_txt .= strip_tags(html_entity_decode(Tools::file_get_contents($template_path . $iso_template . '.txt'), null, 'utf-8'));
         Hook::exec('actionEmailAddAfterContent', array('template' => $template, 'template_html' => &$template_html, 'template_txt' => &$template_txt, 'id_lang' => (int) $id_lang), null, true);
         if ($override_mail && file_exists($template_path . $iso . '/lang.php')) {
             include_once $template_path . $iso . '/lang.php';
         } elseif ($module_name && file_exists($theme_path . 'mails/' . $iso . '/lang.php')) {
             include_once $theme_path . 'mails/' . $iso . '/lang.php';
         } elseif (file_exists(_PS_MAIL_DIR_ . $iso . '/lang.php')) {
             include_once _PS_MAIL_DIR_ . $iso . '/lang.php';
         } else {
             Tools::dieOrLog(Tools::displayError('Error - The language file is missing for:') . ' ' . $iso, $die);
             return false;
         }
         /* Create mail and attach differents parts */
         $subject = '[' . Configuration::get('PS_SHOP_NAME', null, null, $id_shop) . '] ' . $subject;
         $message->setSubject($subject);
         $message->setCharset('utf-8');
         /* Set Message-ID - getmypid() is blocked on some hosting */
         $message->setId(Mail::generateId());
         if (!($reply_to && Validate::isEmail($reply_to))) {
             $reply_to = $from;
         }
         if (isset($reply_to) && $reply_to) {
             $message->setReplyTo($reply_to);
         }
         $template_vars = array_map(array('Tools', 'htmlentitiesDecodeUTF8'), $template_vars);
         $template_vars = array_map(array('Tools', 'stripslashes'), $template_vars);
         if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop))) {
             $logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop);
         } else {
             if (file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop))) {
                 $logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop);
             } else {
                 $template_vars['{shop_logo}'] = '';
             }
         }
         ShopUrl::cacheMainDomainForShop((int) $id_shop);
         /* don't attach the logo as */
         if (isset($logo)) {
             $template_vars['{shop_logo}'] = $message->embed(Swift_Image::fromPath($logo));
         }
         if (Context::getContext()->link instanceof Link === false) {
             Context::getContext()->link = new Link();
         }
         $template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME', null, null, $id_shop));
         $template_vars['{shop_url}'] = Context::getContext()->link->getPageLink('index', true, Context::getContext()->language->id, null, false, $id_shop);
         $template_vars['{my_account_url}'] = Context::getContext()->link->getPageLink('my-account', true, Context::getContext()->language->id, null, false, $id_shop);
         $template_vars['{guest_tracking_url}'] = Context::getContext()->link->getPageLink('guest-tracking', true, Context::getContext()->language->id, null, false, $id_shop);
         $template_vars['{history_url}'] = Context::getContext()->link->getPageLink('history', true, Context::getContext()->language->id, null, false, $id_shop);
         $template_vars['{color}'] = Tools::safeOutput(Configuration::get('PS_MAIL_COLOR', null, null, $id_shop));
         // Get extra template_vars
         $extra_template_vars = array();
         Hook::exec('actionGetExtraMailTemplateVars', array('template' => $template, 'template_vars' => $template_vars, 'extra_template_vars' => &$extra_template_vars, 'id_lang' => (int) $id_lang), null, true);
         $template_vars = array_merge($template_vars, $extra_template_vars);
         $swift->registerPlugin(new Swift_Plugins_DecoratorPlugin(array($to_plugin => $template_vars)));
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT) {
             $message->addPart($template_txt, 'text/plain', 'utf-8');
         }
         if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) {
             $message->addPart($template_html, 'text/html', 'utf-8');
         }
         if ($file_attachment && !empty($file_attachment)) {
             // Multiple attachments?
             if (!is_array(current($file_attachment))) {
                 $file_attachment = array($file_attachment);
             }
             foreach ($file_attachment as $attachment) {
                 if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) {
                     $message->attach(Swift_Attachment::newInstance()->setFilename($attachment['name'])->setContentType($attachment['mime'])->setBody($attachment['content']));
                 }
             }
         }
         /* Send mail */
         $message->setFrom(array($from => $from_name));
         $send = $swift->send($message);
         ShopUrl::resetMainDomainCache();
         if ($send && Configuration::get('PS_LOG_EMAILS')) {
             $mail = new Mail();
             $mail->template = Tools::substr($template, 0, 62);
             $mail->subject = Tools::substr($subject, 0, 254);
             $mail->id_lang = (int) $id_lang;
             $recipients_to = $message->getTo();
             $recipients_cc = $message->getCc();
             $recipients_bcc = $message->getBcc();
             if (!is_array($recipients_to)) {
                 $recipients_to = array();
             }
             if (!is_array($recipients_cc)) {
                 $recipients_cc = array();
             }
             if (!is_array($recipients_bcc)) {
                 $recipients_bcc = array();
             }
             foreach (array_merge($recipients_to, $recipients_cc, $recipients_bcc) as $email => $recipient_name) {
                 /** @var Swift_Address $recipient */
                 $mail->id = null;
                 $mail->recipient = Tools::substr($email, 0, 126);
                 $mail->add();
             }
         }
         return $send;
     } catch (Swift_SwiftException $e) {
         PrestaShopLogger::addLog('Swift Error: ' . $e->getMessage(), 3, null, 'Swift_Message');
         return false;
     }
 }
Example #11
0
 function hookLeftColumn($params)
 {
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = (int) Configuration::get('RSS_FEED_NBR');
     $cacheId = $this->getCacheId($this->name . '-' . date("YmdH"));
     if (!$this->isCached('blockrss.tpl', $cacheId)) {
         // Getting data
         $rss_links = array();
         if ($url && ($contents = Tools::file_get_contents($url))) {
             try {
                 if (@($src = new XML_Feed_Parser($contents))) {
                     for ($i = 0; $i < ($nb ? $nb : 5); $i++) {
                         if (@($item = $src->getEntryByOffset($i))) {
                             $xmlValues = array();
                             foreach (self::$xmlFields as $xmlField) {
                                 $xmlValues[$xmlField] = $item->__get($xmlField);
                             }
                             $xmlValues['enclosure'] = $item->getEnclosure();
                             # Compatibility
                             $xmlValues['url'] = $xmlValues['link'];
                             $rss_links[] = $xmlValues;
                         }
                     }
                 }
             } catch (XML_Feed_Parser_Exception $e) {
                 Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false);
             }
         }
         // Display smarty
         $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links));
     }
     return $this->display(__FILE__, 'blockrss.tpl', $cacheId);
 }
Example #12
0
 protected function deleteImage($image)
 {
     $file_name = $this->uploads_path . $image;
     if (realpath(dirname($file_name)) != realpath($this->uploads_path)) {
         Tools::dieOrLog(sprintf('Could not find upload directory'));
     }
     if ($image != '' && is_file($file_name)) {
         unlink($file_name);
     }
 }
Example #13
0
 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'))) : '');
         $templateVars['{shop_name}'] = Tools::safeOutput(Configuration::get('TM_SHOP_NAME'));
         $templateVars['{shop_url}'] = Tools::getShopDomain(true, true) . __TM_BASE_URI__;
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
         $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
         if ($fileAttachment && isset($fileAttachment['content']) && isset($fileAttachment['name']) && 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;
     }
 }
 private function createCarrier($config, $product_id, $name, $debug_mode = false, &$debug_info = array())
 {
     $carrier = new Carrier();
     if ($debug_mode) {
         array_push($debug_info, "Trying to create carrier " . $product_id . " with name " . $name);
     }
     $carrier->name = $name;
     $carrier->id_zone = $config['id_zone'];
     $carrier->url = $config['url'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behaviour = $config['range_behaviour'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'en') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'no') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
     }
     if ($debug_mode) {
         array_push($debug_info, "Adding carrier");
     }
     if ($carrier->add()) {
         if ($debug_mode) {
             array_push($debug_info, "Carrier added, setting up associations");
         }
         $carriers_str = Configuration::get('FRAKTGUIDE_CREATED_CARRIER_IDS');
         $carriers = $carriers_str ? explode(';', Configuration::get('FRAKTGUIDE_CREATED_CARRIER_IDS')) : array();
         $carriers[] = $carrier->id;
         Configuration::updateValue('FRAKTGUIDE_CREATED_CARRIER_IDS', implode(';', $carriers));
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_zone VALUE(\'' . (int) $carrier->id . '\', \'' . (int) $zone['id_zone'] . '\')');
         }
         $groups = Group::getgroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '10000';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '10000';
         $rangeWeight->add();
         if ($debug_mode) {
             array_push($debug_info, "Trying to update product name table");
         }
         if (!Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'fraktguide_product_names`(`id_carrier`, `product_id`) VALUES(' . $carrier->id . ', \'' . $product_id . '\')')) {
             return false;
         }
         if (!copy(dirname(__FILE__) . '/img/logo.png', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
             return false;
         }
         if ($debug_mode) {
             array_push($debug_info, "Success");
         }
         // Link to correct tax group (ps_carrier_tax_rules_group_shop aparently...)
         if (!Db::getInstance()->insert('carrier_tax_rules_group_shop', array('id_carrier' => $carrier->id, 'id_tax_rules_group' => Configuration::get('FRAKTGUIDE_ID_TAX_RULES_GROUP'), 'id_shop' => Context::getContext()->shop->id))) {
             return false;
         }
         return true;
     } else {
         Tools::dieOrLog("Error creating carrier " . $product_id);
         return false;
     }
 }