Author: David Grudl
Inheritance: extends latte\Object
Esempio n. 1
0
 public function sendMailConsumer(\PhpAmqpLib\Message\AMQPMessage $message)
 {
     $sendMail = json_decode($message->body);
     $latte = new Latte\Engine();
     $sendMail->templateArr->email = $sendMail->to;
     $sendMail->templateArr->subject = $sendMail->subject;
     if (!is_null($sendMail->unsubscribeLink)) {
         $sendMail->templateArr->unsubscribeLink = $sendMail->unsubscribeLink;
     }
     $mail = new Nette\Mail\Message();
     $mail->setFrom($sendMail->from)->addTo($sendMail->to)->setHtmlBody($latte->renderToString($this->config["appDir"] . $this->config['mailer']['templateDir'] . (is_null($sendMail->template) ? $this->config['mailer']['defaultTemplate'] : $sendMail->template), (array) $sendMail->templateArr));
     if (!is_null($sendMail->unsubscribeEmail) || !is_null($sendMail->unsubscribeLink)) {
         $mail->setHeader('List-Unsubscribe', (!is_null($sendMail->unsubscribeEmail) ? '<mailto:' . $sendMail->unsubscribeEmail . '>' : '') . (!is_null($sendMail->unsubscribeEmail) && !is_null($sendMail->unsubscribeLink) ? ", " : "") . (!is_null($sendMail->unsubscribeLink) ? '<' . $sendMail->unsubscribeLink . '>' : ''), TRUE);
     }
     $mail->setSubject($sendMail->subject);
     try {
         $mailer = $this->emailFactory->getConnection($sendMail->connection);
         $mailer->send($mail);
         dump($sendMail->to);
         if ($sendMail->imapSave) {
             $this->saveToImap($mail->generateMessage(), is_null($sendMail->imapFolder) ? $this->config['imap']['sendFolder'] : $sendMail->imapFolder, $sendMail->imapConnection);
         }
         return TRUE;
     } catch (\Exception $e) {
         return FALSE;
     }
 }
Esempio n. 2
0
 /**
  * 
  * @return CacheObject
  */
 public function render(CacheObject $file, Scripter $scripter)
 {
     $this->params['_scripter'] = $scripter;
     $this->params['_scripter_file_rendering'] = $file;
     $file->source = $this->latte->renderToString($file->path, $this->params);
     return $file;
 }
Esempio n. 3
0
 /**
  * @param string $template
  * @param array $values
  * @return string
  */
 public function render($template, array $values = [])
 {
     if (!file_exists("{$this->basePath}/{$template}.latte")) {
         throw new FileNotFoundException();
     }
     return $this->latte->renderToString("{$this->basePath}/{$template}.latte", $values + $this->values);
 }
Esempio n. 4
0
 protected function getLatteEngine()
 {
     if (!isset($this->latteEngine)) {
         $this->latteEngine = new Engine();
         $this->latteEngine->setTempDirectory($this->tempDir);
     }
     return $this->latteEngine;
 }
 public static function install(Engine $latte, $dir)
 {
     $me = new self($latte->getCompiler());
     $me::$dir = $dir;
     $me->addMacro('component', NULL, [$me, 'macroComponentEnd']);
     $me->addMacro('child', NULL, [$me, 'macroChildEnd']);
     $me->addMacro('key', NULL, [$me, 'macroKeyEnd']);
 }
 /**
  * @return \Nette\Bridges\ApplicationLatte\Template
  */
 protected function createTemplate()
 {
     $latte = new Latte\Engine();
     $latte->onCompile[] = function ($latte) {
         Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
     };
     return new Bridges\ApplicationLatte\Template($latte);
 }
Esempio n. 7
0
 /**
  * Gets html content
  *
  * @return mixed
  */
 public function getContent()
 {
     if (is_string($this->content) && file_exists($this->content)) {
         $latte = new Engine();
         return $latte->renderToString($this->content);
     }
     return (string) $this->content;
 }
Esempio n. 8
0
 /**
  * Prepares latte template for email
  *
  * @param string $path
  * @param array $variables
  *
  * @return string
  *
  * @throws InvalidArgumentException
  */
 private function createTemplate($path, $variables = [])
 {
     if (file_exists($path)) {
         return $this->engine->renderToString($path, $variables);
     } else {
         throw new InvalidArgumentException();
     }
 }
Esempio n. 9
0
 /**
  * @param string $email address
  * @param string $name
  * @throws Exception
  */
 public function sendBootstrap($email, $name)
 {
     $msg = new Message();
     $latte = new Engine();
     $args = ['email' => $msg];
     $html = $latte->renderToString($this->getTemplatePath('bootstrap'), $args);
     $msg->setFrom('*****@*****.**', 'Application Name')->addTo($email, $name)->setHtmlBody($html);
     $this->mailer->send($msg);
 }
Esempio n. 10
0
 public function register(Engine $engine)
 {
     if (class_exists('Latte\\Runtime\\FilterInfo')) {
         $engine->addFilter('translate', [$this, 'translateFilterAware']);
     } else {
         $engine->addFilter('translate', [$this, 'translate']);
     }
     $engine->addFilter('getTranslator', [$this, 'getTranslator']);
 }
 public function testConstructor()
 {
     $loader = new FileLoader();
     $latte = new Engine();
     $latte->setLoader($loader);
     $engine = new LatteTransformer(array('latte' => $latte));
     $actual = $engine->renderFile('tests/Fixtures/template.latte', array('name' => 'Linus'));
     $this->assertEquals('Hello, Linus!', $actual);
 }
Esempio n. 12
0
 public function render($toString = false)
 {
     if (!$toString) {
         self::$engine->render(__DIR__ . '/default.latte', $this->getParameters());
     } else {
         return self::$engine->renderToString(__DIR__ . '/default.latte', $this->getParameters());
     }
     return '';
 }
Esempio n. 13
0
 /**
  * @param string $file
  */
 public function save($file = null)
 {
     $this->savePath = $file ?: $this->savePath;
     $dir = dirname($this->savePath);
     if (!is_dir($dir)) {
         mkdir($dir, 0755, true);
     }
     $content = $this->latteEngine->renderToString($this->file, $this->parameters);
     file_put_contents($this->savePath, $content);
 }
Esempio n. 14
0
 /**
  * {@inheritdoc}
  */
 public function render($template, array $values = [], $basePath = null)
 {
     if (!isset($basePath)) {
         $basePath = $this->basePath;
     }
     if (!file_exists("{$basePath}/{$template}")) {
         throw new FileNotFoundException("Cannot find the file, {$basePath}/{$template}");
     }
     return $this->latte->renderToString("{$basePath}/{$template}", $values + $this->values);
 }
Esempio n. 15
0
 public function render($viewFile, $data, $return = false)
 {
     $latte = new Engine();
     $latte->setTempDirectory('runtime');
     if ($return) {
         return $latte->renderToString($viewFile, $data);
     } else {
         return $latte->render($viewFile, $data);
     }
 }
Esempio n. 16
0
 /**
  * Renders HTML code for custom panel.
  *
  * @return string html
  * @internal
  */
 public function getPanel()
 {
     $latte = new Latte\Engine();
     $latte->addFilter('storageId', [$this, 'getStorageId']);
     $latte->addFilter('colorRange', [$this, 'getColorInRange']);
     $args = ['title' => $this->getTitle(), 'collector' => $this->collector];
     if ($this->collector->getQueries()) {
         $this->extremes = $this->collector->getTimeExtremes();
     }
     return $latte->renderToString(__DIR__ . '/queryPanel.latte', $args);
 }
Esempio n. 17
0
 /**
  * @param string $path
  * @param array $params
  * @param bool $mustClean
  */
 public function render($path, $params, $mustClean = FALSE)
 {
     $this->initServices($params);
     // Render the view
     $content = $this->latte->renderToString($path, $params);
     if ($mustClean) {
         $this->_view->setContent($content);
     } else {
         echo $content;
     }
 }
 /**
  * @param Nette\Application\UI\Form $form
  */
 public function contactFormSubmitted(Nette\Application\UI\Form $form)
 {
     $values = $form->getValues();
     if ($this->context->getParameters()["send_emails"]) {
         $latte = new Engine();
         $mail = new Message();
         $mail->setFrom($this->context->getParameters()["mailer_mail"])->addTo($this->context->getParameters()["mailer_mail"])->setHtmlBody($latte->renderToString(__DIR__ . '/templates/Contact/email.latte', array("email" => $values->email, "content" => $values->content)));
         $mailer = new Nette\Mail\SmtpMailer(array('host' => $this->context->getParameters()["mailer_host"], 'username' => $this->context->getParameters()["mailer_mail"], 'password' => $this->context->getParameters()["mailer_password"], 'secure' => 'ssl'));
         $mailer->send($mail);
     }
     $this->redirect("Contact:sent");
 }
 protected function buildFileFromTemplate($file, $template, $args = [], $prefix = '')
 {
     if (is_file($file)) {
         throw new InvalidStateException("File '{$file}' already exists");
     }
     $dir = dirname($file);
     if (!is_dir($dir)) {
         mkdir($dir);
     }
     $latte = new Engine();
     $content = $prefix . $latte->renderToString(__DIR__ . "/../scaffolds/{$template}.latte", $args);
     file_put_contents($file, $content);
 }
Esempio n. 20
0
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface   $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values      Values to use during rendering
  * @return string The script output.
  * @throws \LogicException
  */
 public function render($nameOrModel, $values = null)
 {
     $name = $nameOrModel;
     if ($nameOrModel instanceof ModelInterface) {
         $name = $this->resolver->resolve($nameOrModel->getTemplate(), $this);
         $values = (array) $nameOrModel->getVariables();
     }
     if (array_key_exists('helper', $values)) {
         throw new \LogicException('Variable $helper is reserved for Zend helpers and can\'t be passed to view.');
     }
     $values['helper'] = $this->helpers;
     return $this->engine->renderToString($name, $values);
 }
Esempio n. 21
0
 public function addItem(IItem $item)
 {
     if (!$this->prepared) {
         $this->prepare();
     }
     if ($item->validate()) {
         $latte = new Latte\Engine();
         $xmlItem = $latte->renderToString($this->getTemplate('item'), ['product' => $item]);
         fwrite($this->handle, $xmlItem);
     } else {
         throw new ItemIncompletedException('Item is not complete');
     }
 }
Esempio n. 22
0
 /** Funkcia pre odoslanie emailu
  * @param array $params Parametre správy
  * @param string $subjekt Subjekt emailu
  * @return string Zoznam komu bol odoslany email
  * @throws SendException
  */
 public function send($params, $subjekt)
 {
     $templ = new Latte\Engine();
     $this->mail->setFrom($params["site_name"] . ' <' . $this->from . '>');
     $this->mail->setSubject($subjekt)->setHtmlBody($templ->renderToString($this->template, $params));
     try {
         $sendmail = new SendmailMailer();
         $sendmail->send($this->mail);
         return $this->email_list;
     } catch (Exception $e) {
         throw new SendException('Došlo k chybe pri odosielaní e-mailu. Skúste neskôr znovu...' . $e->getMessage());
     }
 }
Esempio n. 23
0
 /**
  * Gets html content
  *
  * @return string|Template
  */
 public function getContent()
 {
     if ($this->content instanceof Template) {
         // if is it template
         return $this->content->render();
     } else {
         if (file_exists($this->content)) {
             // if is it file
             $l = new Engine();
             return $l->renderToString($this->content);
         }
     }
     return (string) $this->content;
 }
Esempio n. 24
0
 public function sendEmail($email = null, $latte_name, $product, $winners_bid, $cost, $title)
 {
     if ($email != null || $email != "") {
         // nastaveni parametru pro latte emailu
         $latte = new Latte\Engine();
         $params = array('product' => $product, 'winners_bid' => $winners_bid, 'cost' => $cost, 'title' => $title);
         // nastaveni mailu
         $mail = new Nette\Mail\Message();
         $mail->setFrom($this->mailer['username'])->addTo($email)->setHtmlBody($latte->renderToString(__DIR__ . '/../presenters/templates/Email/' . $latte_name . '.latte', $params));
         // poslani mailu
         $mailer = new Nette\Mail\SmtpMailer($this->mailer);
         $mailer->send($mail);
     }
 }
Esempio n. 25
0
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('latte.engine', function ($app) {
         $latte = new Latte\Engine();
         $latte->setTempDirectory($app['config']['view.compiled']);
         return $latte;
     });
     $this->app->singleton('latte.globals', function ($app) {
         return new LatteGlobals();
     });
     $this->app->bind('view', function ($app) {
         return new LatteFactory($app);
     });
 }
Esempio n. 26
0
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(Engine::class, function () {
         $engine = new Engine();
         $engine->setLoader(new FileLoader());
         $cachePath = config('view.cache');
         if ($cachePath) {
             $engine->setTempDirectory(path($cachePath));
         }
         return $engine;
     });
     $app->closure(RenderInterface::class, function ($app) {
         return new LatteView($app[Engine::class], path(config('view.path')));
     });
 }
Esempio n. 27
0
 /**
  * Setting templating system.
  * @return Engine
  */
 private function createLatteEngine()
 {
     // Create directory.
     $temp = $this->temp . '/_Latte.TemplateCache';
     if (!is_dir($temp)) {
         FileSystem::createDir($temp);
     }
     $latte = new Engine();
     $latte->setTempDirectory($temp);
     // Macro for forms.
     $latte->onCompile[] = function ($latte) {
         FormMacros::install($latte->getCompiler());
     };
     return $latte;
 }
Esempio n. 28
0
 public function register(Engine $engine)
 {
     $engine->addFilter('imageSize', function ($imagePath) {
         return $this->imageSize($imagePath);
     });
     $engine->addFilter('nl2ul', function ($text, $class) {
         return $this->nl2ul($text, $class);
     });
     $engine->addFilter('correctUrl', function ($url) {
         return $this->correctUrl($url);
     });
     $engine->addFilter('hideIpPart', function ($ip, $hideParts = 1) {
         return $this->hideIpPart($ip, $hideParts);
     });
 }
Esempio n. 29
0
 /**
  * Register the application services.
  *
  * @return void
  * @throws \InvalidArgumentException
  */
 public function register()
 {
     $this->app->singleton('latte.engine', function ($app) {
         $latte = new Latte\Engine();
         $latte->setAutoRefresh($app['config']['app.debug']);
         $latte->setTempDirectory($app['config']['view.compiled']);
         return $latte;
     });
     $this->app->resolving('view', function (Factory $viewFactory, Application $app) {
         if ($viewFactory instanceof \Illuminate\View\Factory) {
             $viewFactory->addExtension('latte', 'latte', function () use($app) {
                 return new LatteEngineBridge($app['latte.engine']);
             });
         } else {
             throw new \InvalidArgumentException('Can\'t register Latte\\Engine, ' . get_class($viewFactory) . ' view factory is not supported.');
         }
     });
 }
Esempio n. 30
0
 public function &__get($name)
 {
     switch (strtolower($name)) {
         case 'parser':
         case 'compiler':
             $method = 'get' . ucfirst($name);
             trigger_error("Magic getters are deprecated. Use {$method}() method instead.", E_USER_DEPRECATED);
             $return = $this->{$method}();
             // return by reference
             return $return;
     }
     return parent::__get($name);
 }