/** * @return Template */ public function createTemplate(UI\Control $control = NULL) { $latte = $this->latteFactory->create(); $template = new Template($latte); $presenter = $control ? $control->getPresenter(FALSE) : NULL; if ($control instanceof UI\Presenter) { $latte->setLoader(new Loader($control)); } if ($latte->onCompile instanceof \Traversable) { $latte->onCompile = iterator_to_array($latte->onCompile); } array_unshift($latte->onCompile, function ($latte) use($control, $template) { $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler())); UIMacros::install($latte->getCompiler()); if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) { Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler()); } if ($control) { $control->templatePrepareFilters($template); } }); $latte->addFilter('url', 'rawurlencode'); // back compatiblity foreach (['normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse'] as $name) { $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name); } $latte->addFilter('null', function () { }); $latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) { return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit); // intentionally == }); if (!isset($latte->getFilters()['translate'])) { $latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi) { throw new Nette\InvalidStateException('Translator has not been set. Set translator using $template->setTranslator().'); }); } // default parameters $template->user = $this->user; $template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL; $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl); $template->flashes = []; if ($control) { $template->control = $control; $template->presenter = $presenter; $latte->addProvider('uiControl', $control); $latte->addProvider('uiPresenter', $presenter); $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($control)); } $latte->addProvider('cacheStorage', $this->cacheStorage); // back compatibility $template->_control = $control; $template->_presenter = $presenter; $template->netteCacheStorage = $this->cacheStorage; if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) { $id = $control->getParameterId('flash'); $template->flashes = (array) $presenter->getFlashSession()->{$id}; } return $template; }
public function createTemplate($class = NULL) { $latte = $this->latteFactory->create(); $template = $class ? new $class($latte) : new Template($latte); $template->getLatte()->addFilter(NULL, 'Nette\\Templating\\Helpers::loader'); if ($latte->onCompile instanceof Traversable) { $latte->onCompile = iterator_to_array($latte->onCompile); } array_unshift($latte->onCompile, function ($latte) { $latte->getParser()->shortNoEscape = TRUE; $latte->getCompiler()->addMacro('cache', new CacheMacro($latte->getCompiler())); UIMacros::install($latte->getCompiler()); FormMacros::install($latte->getCompiler()); }); $latte->addFilter('url', 'rawurlencode'); // back compatiblity foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) { $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name); } $template->user = $this->user; $template->netteHttpResponse = $this->httpResponse; $template->netteCacheStorage = $this->httpRequest; $template->baseUri = $template->baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/'); $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl); if (!isset($template->flashes) || !is_array($template->flashes)) { $template->flashes = array(); } $template->setTranslator($this->translator); $template->_control = $this->linker; return $template; }
/** * @return Latte\Engine */ protected function createLatte() { $latte = $this->latteFactory->create(); // Base macros Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler()); // Button macros ButtonMacros::install($latte->getCompiler()); return $latte; }
private function createMessageFromTemplate(ILatteLoader $loader, $name, $parameters) { $latte = $this->latteFactory->create(); $latte->onCompile[] = function (Engine $latte) { MessageMacros::install($latte->getCompiler()); }; $latte->setLoader($loader)->renderToString($name, array('_message' => $message = new Message()) + $parameters); return $message; }
public function renderReader() { $this->getHttpResponse()->setContentType('text/plain', 'UTF-8'); $this->template->method = $this->getHttpRequest()->getMethod(); if ($this->template->method == 'POST') { # \Tracy\Debugger::$productionMode = TRUE; $raceinfo = $this->race->getRaceInfo(); $jsondata = $this->getHttpRequest()->getRawBody(); $jsdata = Json::decode($jsondata); if (isset($jsdata->init)) { if ($raceinfo) { $this->sendResponse(new JsonResponse(['status' => 'OK'])); } else { $this->sendResponse(new JsonResponse(['status' => 'Err', 'error' => 'NoRace'])); } } else { $data['si_number'] = $jsdata->si_number; $data['si_type'] = $jsdata->si_type; $data['si_lname'] = $jsdata->si_lname; $data['si_fname'] = $jsdata->si_fname; $data['tm_clear'] = $jsdata->clear->tst == 0 ? NULL : $jsdata->clear->time; $data['tm_check'] = $jsdata->check->tst == 0 ? NULL : $jsdata->check->time; $data['tm_start'] = $jsdata->start->tst == 0 ? NULL : $jsdata->start->time; $data['tm_finish'] = $jsdata->finish->tst == 0 ? NULL : $jsdata->finish->time; $punches = []; foreach ($jsdata->punches as $punch) { $punches[] = ['cpcode' => $punch->cn, 'cptime' => $punch->tst == 0 ? NULL : $punch->time]; } $this->reader->insertRead($data, $punches); // Data for displaying or printing $data['si_name'] = $data['si_fname'] . ' ' . $data['si_lname']; if ($data['si_name'] == ' ') { $data['si_name'] = ''; } list($data['clear'], , , ) = $this->reader->timeMake($jsdata->clear->time, $jsdata->clear->tst, $raceinfo['time_0']); list($data['check'], , , ) = $this->reader->timeMake($jsdata->check->time, $jsdata->check->tst, $raceinfo['time_0']); list($data['start'], $lastpunch, , ) = $this->reader->timeMake($jsdata->start->time, $jsdata->start->tst, $raceinfo['time_0']); list($data['finish'], , , ) = $this->reader->timeMake($jsdata->finish->time, $jsdata->finish->tst, $raceinfo['time_0']); if ($lastpunch == 0) { $lastpunch = $raceinfo['time_0']; } $i = 0; foreach ($jsdata->punches as $punch) { list($punches[$i]['time_s'], $lastpunch, $punches[$i]['split_s'], ) = $this->reader->timeMake($punch->time, $punch->tst, $lastpunch); $i++; } $params = ['data' => $data, 'punches' => $punches, 'time_0' => $this->reader->timeFormat($raceinfo['time_0'])]; $latte = $this->latteFactory->create(); $printer_out = $latte->renderToString('../app/templates/Reader/print.latte', $params); $display_out = $latte->renderToString('../app/templates/Reader/display.latte', $params); $this->sendResponse(new JsonResponse(['printer_out' => $printer_out, 'display_out' => $display_out])); } } else { $this->template->raceid = $this->raceid; } }
/** * @return Latte\Engine * @throws \NForms\Exceptions\InvalidStateException */ protected function createLatte() { if (!$this->latteFactory) { throw new InvalidStateException("Please inject Latte factory."); } $latte = $this->latteFactory->create(); FormMacros::install($latte->getCompiler()); ButtonMacros::install($latte->getCompiler()); return $latte; }
/** * @return Template */ public function createTemplate(UI\Control $control) { $latte = $this->latteFactory->create(); $template = new Template($latte); $presenter = $control->getPresenter(FALSE); if ($control instanceof UI\Presenter) { $latte->setLoader(new Loader($control)); } if ($latte->onCompile instanceof \Traversable) { $latte->onCompile = iterator_to_array($latte->onCompile); } array_unshift($latte->onCompile, function ($latte) use ($control, $template) { $latte->getParser()->shortNoEscape = TRUE; $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler())); UIMacros::install($latte->getCompiler()); if (class_exists('Nette\Bridges\FormsLatte\FormMacros')) { Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler()); } $control->templatePrepareFilters($template); }); $latte->addFilter('url', 'rawurlencode'); // back compatiblity foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) { $latte->addFilter($name, 'Nette\Utils\Strings::' . $name); } $latte->addFilter('null', function () {}); $latte->addFilter('length', function ($var) { return is_string($var) ? Nette\Utils\Strings::length($var) : count($var); }); $latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) { return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit); // intentionally == }); // default parameters $template->control = $template->_control = $control; $template->presenter = $template->_presenter = $presenter; $template->user = $this->user; $template->netteHttpResponse = $this->httpResponse; $template->netteCacheStorage = $this->cacheStorage; $template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL; $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl); $template->flashes = array(); if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) { $id = $control->getParameterId('flash'); $template->flashes = (array) $presenter->getFlashSession()->$id; } return $template; }
/** * @param Message $mail * @param string $body * @param array|NULL $params */ public function send(Message $mail, $body = NULL, array $params = NULL) { if ($body) { $latte = $this->latteFactory->create(); $latte->setLoader(new StringLoader()); $latte->addProvider('uiControl', $this->linkGenerator); UIMacros::install($latte->getCompiler()); $params = (array) $params; // can be NULL $html = $latte->renderToString($body, $params); $mail->setHtmlBody($html); } $this->mailer->send($mail); }
/** * Creates template and registers helpers and latte filter * @param UI\Presenter $presenter * @param string $file Filepath to file * @param string|NULL $lang Lang code (length=2) * @param string $class Name of template class * @throws InvalidArgumentException * @return Nette\Templating\IFileTemplate */ public function createTemplate(UI\Presenter $presenter, $file = NULL, $lang = NULL, $class = NULL) { $this->translator->setLangTo($lang); $latte = $this->latteFactory->create(); $template = $class ? new $class($latte) : new Nette\Bridges\ApplicationLatte\Template($latte); $template->getLatte()->addFilter(NULL, 'Nette\\Templating\\Helpers::loader'); $template->getLatte()->addFilter(NULL, '\\Helpers::loader'); array_unshift($latte->onCompile, function ($latte) { $latte->getParser()->shortNoEscape = TRUE; $latte->getCompiler()->addMacro('cache', new CacheMacro($latte->getCompiler())); Nette\Bridges\ApplicationLatte\UIMacros::install($latte->getCompiler()); FormMacros::install($latte->getCompiler()); }); $latte->addFilter('url', 'rawurlencode'); // back compatiblity foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) { $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name); } $template->setTranslator($this->translator); if (!is_null($file)) { $template->setFile($this->appDir . $file); } // default parameters $template->control = $template->_control = $presenter; $template->presenter = $template->_presenter = $presenter; if ($presenter instanceof UI\Presenter) { $template->user = $presenter->getUser(); $template->netteHttpResponse = $this->httpResponse; $template->netteCacheStorage = $this->netteCacheStorage; $template->baseUri = $template->baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/'); $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl); // flash message if ($presenter->hasFlashSession()) { $id = $presenter->getParameterId('flash'); $template->flashes = $presenter->getFlashSession()->{$id}; } } if (!isset($template->flashes) || !is_array($template->flashes)) { $template->flashes = array(); } return $template; }
/** * @return Template */ public function createTemplate(UI\Control $control) { $latte = $this->latteFactory->create(); $template = new Template($latte); $presenter = $control->getPresenter(FALSE); if ($control instanceof UI\Presenter) { $latte->setLoader(new Loader($control)); } if ($latte->onCompile instanceof \Traversable) { $latte->onCompile = iterator_to_array($latte->onCompile); } array_unshift($latte->onCompile, function ($latte) use($control, $template) { $latte->getParser()->shortNoEscape = TRUE; $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler())); UIMacros::install($latte->getCompiler()); Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler()); $control->templatePrepareFilters($template); }); $latte->addFilter('url', 'rawurlencode'); // back compatiblity foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) { $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name); } // default parameters $template->control = $template->_control = $control; $template->presenter = $template->_presenter = $presenter; $template->user = $this->user; $template->netteHttpResponse = $this->httpResponse; $template->netteCacheStorage = $this->cacheStorage; $template->baseUri = $template->baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/'); $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl); $template->flashes = array(); if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) { $id = $control->getParameterId('flash'); $template->flashes = (array) $presenter->getFlashSession()->{$id}; } return $template; }
function get($validate = TRUE, $parseSubject = TRUE) { $required = ['from', 'to', 'subject', 'content']; $args = ['from' => $this->from, 'fromName' => $this->fromName, 'to' => $this->to, 'toName' => $this->toName, 'replyTo' => is_null($this->replyTo) ? $this->from : $this->replyTo, 'replyToName' => is_null($this->replyTo) ? $this->fromName : $this->replyToName, 'subject' => $parseSubject ? $this->getSubject() : $this->subjectDefault, 'content' => $this->content, 'attachments' => $this->attachments]; if (!is_null($this->unsubscribeEmail)) { $args['unsubscribeEmail'] = $this->unsubscribeEmail; } if (!is_null($this->unsubscribeLink)) { $args['unsubscribeLink'] = $this->unsubscribeLink; } if (is_null($this->content) && !is_null($this->template)) { foreach ($this->templateArgsMinimum as $v) { if (!isset($this->templateArgs[$v])) { if ($validate) { trigger_error('Missing templateArgs.' . $v); $this->templateArgs[$v] = ''; } } } if ($validate) { $latte = $this->latteFactory->create(); $latte->addProvider('uiControl', $this->linkGenerator); $latte->addProvider('uiPresenter', $this->linkGenerator); $args['_url'] = $this->refUrl; Nette\Bridges\ApplicationLatte\UIMacros::install($latte->getCompiler()); foreach ($this->latteSetupFilterCallback as $v) { $v($latte); } $args['content'] = $latte->renderToString($this->template, $args + $this->templateArgs); } } foreach ($required as $v) { if (is_null($args[$v])) { if ($validate) { trigger_error('Missing ' . $v); $args[$v] = ''; } } } return (object) $args; }