public function send() { ClassLoader::ignoreMissingClasses(); $this->application->processInstancePlugins('email-prepare-send', $this); $this->application->processInstancePlugins('email-prepare-send/' . $this->relativeTemplatePath, $this); if ($this->template) { $originalLocale = $this->application->getLocale(); $emailLocale = Locale::getInstance($this->getLocale()); $this->application->setLocale($emailLocale); $this->application->getLocale()->translationManager()->loadFile('User'); $this->application->loadLanguageFiles(); $smarty = $this->application->getRenderer()->getSmartyInstance(); foreach ($this->values as $key => $value) { $smarty->assign($key, $value); } $router = $this->application->getRouter(); $smarty->assign('html', false); $smarty->disableTemplateLocator(); $text = $smarty->fetch($this->template); $smarty->enableTemplateLocator(); $parts = explode("\n", $text, 2); $this->subject = array_shift($parts); $this->setText(array_shift($parts)); // fix URLs $this->text = str_replace('&', '&', $this->text); if ($this->application->getConfig()->get('HTML_EMAIL')) { $smarty->assign('html', true); $html = array_pop(explode("\n", $smarty->fetch($this->template), 2)); $css = new EditedCssFile('email'); $smarty->assign('cssStyle', str_replace("\n", ' ', $css->getCode())); $smarty->assign('messageHtml', $html); $html = $smarty->fetch($this->getTemplatePath('htmlWrapper')); $this->setHtml($html); } $this->application->setLocale($originalLocale); } $this->application->processInstancePlugins('email-before-send', $this); $this->application->processInstancePlugins('email-before-send/' . $this->relativeTemplatePath, $this); $this->message->setSubject($this->subject); if ($this->html) { preg_match_all('/\\#\\#([_\\-\\.a-zA-Z0-9\\/]+)\\#\\#/msU', $this->html, $matches); $html = $this->html; if (!empty($matches[1])) { foreach ($matches[1] as $match) { $html = str_replace('##' . $match . '##', $this->message->embed(Swift_Image::fromPath(ClassLoader::getRealPath('public.') . $match)), $html); } } preg_match_all('/src\\=\\"([\\:_\\-\\.a-zA-Z0-9\\/]+)\\"/msU', $this->html, $matches); if (!empty($matches[1])) { foreach ($matches[1] as $match) { if (substr($match, 0, 4) == 'http') { if (substr($match, 0, strlen($this->url)) == $this->url) { $match = substr($match, strlen($this->url)); } } if (!substr($match, 0, 4) == 'http') { $match = $this->message->embed(Swift_Image::fromPath(ClassLoader::getRealPath('public.') . $match)); } $html = str_replace('src="' . $match . '"', 'src="' . $match . '"', $html); } $html = str_replace('src="upload', 'src="' . $this->url . '/upload', $html); } $this->message->setBody($html, 'text/html'); } if ($this->text) { if (!$this->html) { $this->message->setBody($this->text, 'text/plain'); } else { $this->message->addPart($this->text, 'text/plain'); } } if (!$this->text && !$this->html) { return false; } try { $res = $this->swiftInstance->send($this->message); ClassLoader::ignoreMissingClasses(false); } catch (Exception $e) { $this->application->processInstancePlugins('email-fail-send/' . $this->relativeTemplatePath, $this, array('exception' => $e)); $this->application->processInstancePlugins('email-fail-send', $this, array('exception' => $e)); ClassLoader::ignoreMissingClasses(false); return false; } $this->application->processInstancePlugins('email-after-send/' . $this->relativeTemplatePath, $this); $this->application->processInstancePlugins('email-after-send', $this); return $res; }
public function cssIframe() { $this->setLayout('empty'); $theme = $this->request->get('theme'); $css = new EditedCssFile($theme); if (!$css->getCode()) { $css->setCode(' '); $css->save(); } $response = new ActionResponse(); $response->set('theme', $theme); $response->set('file', $css->getFileName()); return $response; }
public function send() { ClassLoader::ignoreMissingClasses(); $this->application->processInstancePlugins('email-prepare-send', $this); $this->application->processInstancePlugins('email-prepare-send/' . $this->relativeTemplatePath, $this); if ($this->template) { $originalLocale = $this->application->getLocale(); $emailLocale = Locale::getInstance($this->getLocale()); $this->application->setLocale($emailLocale); $this->application->getLocale()->translationManager()->loadFile('User'); $this->application->loadLanguageFiles(); $smarty = $this->application->getRenderer()->getSmartyInstance(); foreach ($this->values as $key => $value) { $smarty->assign($key, $value); } $router = $this->application->getRouter(); $smarty->assign('html', false); $smarty->disableTemplateLocator(); $text = $smarty->fetch($this->template); $smarty->enableTemplateLocator(); $parts = explode("\n", $text, 2); $this->subject = array_shift($parts); $this->setText(array_shift($parts)); // fix URLs $this->text = str_replace('&', '&', $this->text); if ($this->application->getConfig()->get('HTML_EMAIL')) { $smarty->assign('html', true); $html = array_pop(explode("\n", $smarty->fetch($this->template), 2)); $css = new EditedCssFile('email'); $smarty->assign('cssStyle', str_replace("\n", ' ', $css->getCode())); $smarty->assign('messageHtml', $html); $html = $smarty->fetch($this->getTemplatePath('htmlWrapper')); $this->setHtml($html); } $this->application->setLocale($originalLocale); } $this->application->processInstancePlugins('email-before-send', $this); $this->application->processInstancePlugins('email-before-send/' . $this->relativeTemplatePath, $this); $this->message->setSubject($this->subject); if ($this->html) { $this->message->setBody($this->html, 'text/html'); } if ($this->text) { if (!$this->html) { $this->message->setBody($this->text, 'text/plain'); } else { $this->message->addPart($this->text, 'text/plain'); } } if (!$this->text && !$this->html) { return false; } try { $res = $this->swiftInstance->send($this->message); ClassLoader::ignoreMissingClasses(false); } catch (Exception $e) { $this->application->processInstancePlugins('email-fail-send/' . $this->relativeTemplatePath, $this, array('exception' => $e)); $this->application->processInstancePlugins('email-fail-send', $this, array('exception' => $e)); ClassLoader::ignoreMissingClasses(false); return false; } $this->application->processInstancePlugins('email-after-send/' . $this->relativeTemplatePath, $this); $this->application->processInstancePlugins('email-after-send', $this); return $res; }