コード例 #1
0
ファイル: Template.php プロジェクト: enlitepro/enlite-mail
 /**
  * @param Message $message
  * @return Message
  */
 public function render(Message $message)
 {
     $viewModel = new ViewModel($this->variables);
     $viewModel->setTemplate($this->template);
     $helperPluginManager = $this->renderer->getHelperPluginManager();
     /** @var HeadTitle $helper */
     $helper = $helperPluginManager->get('HeadTitle');
     // replace headTitle
     $headTitle = new HeadTitle();
     $headTitle->setAutoEscape(false);
     $helperPluginManager->setAllowOverride(true);
     $helperPluginManager->setService('HeadTitle', $headTitle);
     if (!$message->getBody()) {
         $message->setBody(new MimeMessage());
     }
     $text = new Part($this->renderer->render($viewModel));
     $text->charset = 'UTF-8';
     $text->boundary = $message->getBody()->getMime()->boundary();
     $text->encoding = Mime::ENCODING_BASE64;
     $text->type = Mime::TYPE_HTML;
     $message->getBody()->addPart($text);
     $message->setSubject($headTitle->renderTitle());
     // hack for ZF
     $message->setBody($message->getBody());
     // restore original helper
     $helperPluginManager->setService('HeadTitle', $helper);
     return $message;
 }
コード例 #2
0
 /**
  * @param RenderableMailInterface $mail
  *
  * @return string
  */
 protected function renderContent(RenderableMailInterface $mail)
 {
     $viewModel = new ViewModel();
     $viewModel->setTemplate($mail->getViewFile());
     $viewModel->setTerminal(true);
     $viewModel->setVariables($mail->getParams());
     return $this->viewRenderer->render($viewModel);
 }
コード例 #3
0
ファイル: Template.php プロジェクト: t4web/mail
 /**
  * @param array $data
  * @return string
  */
 public function getBody(array $data = [])
 {
     $viewContent = new ViewModel($data);
     $viewContent->setTemplate($this->template);
     $content = $this->renderer->render($viewContent);
     $this->layout->setVariable('content', $content);
     return $this->renderer->render($this->layout);
 }
コード例 #4
0
 public function onSendEmail(Event $e)
 {
     /** @var QueueInterface $queue */
     $queue = $this->queues->get('user');
     $emailJob = $queue->getJobPluginManager()->get(SendEmailJob::class);
     $email = $e->getParams();
     $html = $this->renderer->render($email->getHtmlTemplate(), $email->getVars());
     $text = $this->renderer->render($email->getTextTemplate(), $email->getVars());
     $message = new MessageStruct();
     $message->html = $html;
     $message->text = $text;
     $message->to = $email->getTo();
     $emailJob->setContent($message);
     $queue->push($emailJob);
 }
コード例 #5
0
ファイル: SxMail.php プロジェクト: rwoverdijk/sxmail
 /**
  * Manipulate the body based on configuration options.
  *
  * @param   mixed   $body
  * @param   string  $mimeType
  *
  * @return  string
  */
 protected function manipulateBody($body, $mimeType = null)
 {
     // Make sure we have a string.
     if ($body instanceof ViewModel) {
         $body = $this->viewRenderer->render($body);
         $detectedMimeType = 'text/html';
     } elseif (null === $body) {
         $detectedMimeType = 'text/plain';
         $body = '';
     }
     if (null !== ($layout = $this->getLayout())) {
         $layout->setVariables(array('content' => $body));
         $detectedMimeType = 'text/html';
         $body = $this->viewRenderer->render($layout);
     }
     if (null === $mimeType && !isset($detectedMimeType)) {
         $mimeType = preg_match("/<[^<]+>/", $body) ? 'text/html' : 'text/plain';
     } elseif (null === $mimeType) {
         $mimeType = $detectedMimeType;
     }
     $mimePart = new MimePart($body);
     $mimePart->type = $mimeType;
     $message = new MimeMessage();
     if (!isset($this->config['message']['generate_alternative_body'])) {
         $this->config['message']['generate_alternative_body'] = true;
     }
     if ($this->config['message']['generate_alternative_body'] && $mimeType === 'text/html') {
         $generatedBody = $this->renderTextBody($body);
         $altPart = new MimePart($generatedBody);
         $altPart->type = 'text/plain';
         $message->addPart($altPart);
     }
     $message->addPart($mimePart);
     return $message;
 }
コード例 #6
0
ファイル: ChartJsSpec.php プロジェクト: phpro/zf-charts
 public function it_should_render_chartjs_charts(Renderer $view, ChartInterface $chart)
 {
     $view->render(Argument::that(function ($viewModel) use($chart) {
         return $viewModel instanceof ViewModel && $viewModel->getTemplate() === 'zf-charts/chartjs' && $viewModel->getVariable('chart') === $chart->getWrappedObject() && $viewModel->getVariable('width') === 100 && $viewModel->getVariable('height') === 100 && $viewModel->getVariable('showLegend') === false;
     }))->willReturn('chart-html');
     $this->markAsInitialized(true);
     $this->render($chart, ['width' => 100, 'height' => 100, 'show_legend' => false])->shouldBe('chart-html');
 }
コード例 #7
0
 /**
  * Notify user via sending mail
  * 
  * @access public
  * @param array $mailArray
  * @throws \Exception Missing some required Mail option(s)
  */
 public function notify($mailArray)
 {
     $requiredKeys = array('from', 'to', 'subject', 'templateName', 'templateParameters');
     if (count(array_intersect_key(array_flip($requiredKeys), $mailArray)) !== count($requiredKeys)) {
         throw new \Exception("Missing some required Mail option(s)");
     }
     $mailViewModel = new ViewModel($mailArray['templateParameters']);
     $mailViewModel->setTemplate("notifications/mail/" . $mailArray['templateName']);
     $layout = new ViewModel();
     $layout->setTemplate("notifications/mail/layout");
     $layout->setVariable("emailBody", $this->viewRenderer->render($mailViewModel));
     $htmlMarkup = $this->viewRenderer->render($layout);
     $html = new MimePart($htmlMarkup);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $mailArray["body"] = $body;
     $this->sendEmailJob->setContent($mailArray);
     $this->queue->push($this->sendEmailJob);
 }
コード例 #8
0
ファイル: Email.php プロジェクト: arbi/MyCode
 /**
  * Render a given template with given data assigned.
  *
  * @param  string $tpl
  * @param  array  $data
  * @return string The rendered content.
  */
 protected function renderMail($tpl, array $data)
 {
     $viewModel = new ViewModel($data);
     if (isset($data['layout'])) {
         $viewModel->setTemplate('layout/' . $data['layout']);
     } else {
         $viewModel->setTemplate('layout/layout');
     }
     $viewModel->setVariables(['template' => $tpl]);
     return $this->renderer->render($viewModel);
 }
コード例 #9
0
 /**
  * Callback that does the work of injecting the toolbar into the response
  *
  * @param  MvcEvent $event
  * @return void
  */
 public function injectToolbar(MvcEvent $event)
 {
     if (!$this->shouldRender()) {
         return;
     }
     $formManager = $this->serviceLocator->get('FormElementManager');
     $select = $formManager->get('NetgluePrismic\\Form\\Element\\SelectPrismicRef');
     $request = $event->getApplication()->getRequest();
     $url = (string) $request->getUri();
     $response = $event->getApplication()->getResponse();
     $toolbarView = new ViewModel();
     $toolbarView->selectRef = $select;
     $toolbarView->url = $url;
     $toolbarView->setTemplate('netglue-prismic/toolbar/toolbar');
     $toolbar = $this->renderer->render($toolbarView);
     $toolbarCss = new ViewModel();
     $toolbarCss->setTemplate('netglue-prismic/toolbar/styles');
     $style = $this->renderer->render($toolbarCss);
     $injected = preg_replace('/<\\/body>/i', $toolbar . "\n</body>", $response->getBody(), 1);
     $injected = preg_replace('/<\\/head>/i', $style . "\n</head>", $injected, 1);
     $response->setContent($injected);
 }
コード例 #10
0
    /**
     * Render a view script (optionally to a named response segment)
     *
     * Sets the noRender flag to true when called.
     *
     * @param  string $script
     * @param  string $name
     * @return void
     */
    public function renderScript($script, $name = null)
    {
        if (null === $name) {
            $name = $this->getResponseSegment();
        }

        $this->getResponse()->appendBody(
            $this->view->render($script),
            $name
        );

        $this->setNoRender();
    }
コード例 #11
0
 /**
  * @param \Zend\View\Renderer\RendererInterface $viewRenderer
  */
 public function it_should_render_a_html_body($viewRenderer)
 {
     $mail = $this->getMailStub();
     $parsedTemplate = '<html><body></body></html>';
     $parsedBody = '<body></body>';
     // Lay-out rendering
     $viewRenderer->render(Argument::type('Zend\\View\\Model\\ViewModel'))->will(function ($arguments) use($mail, $parsedBody, $parsedTemplate) {
         $viewModel = $arguments[0];
         if ($mail->getLayoutFile() == $viewModel->getTemplate()) {
             return sprintf('<html>%s</html>', $viewModel->getVariables()['mailBody']);
         } else {
             return $parsedBody;
         }
     });
     // Run method:
     $html = $this->render($mail);
     $html->shouldBe($parsedTemplate);
 }
コード例 #12
0
ファイル: QrCodeHelper.php プロジェクト: acelaya/zf2-acqrcode
 /**
  * Renders a img tag with a base64-encoded QR code
  * @param string $message
  * @param string|null $extension
  * @param int|null $size
  * @param null $padding
  * @param array $attribs
  * @return mixed
  */
 public function renderBase64Img($message, $extension = null, $size = null, $padding = null, $attribs = array())
 {
     if (isset($extension)) {
         if (is_array($extension)) {
             $attribs = $extension;
             $extension = null;
         } elseif (isset($size)) {
             if (is_array($size)) {
                 $attribs = $size;
                 $size = null;
             } elseif (isset($padding) && is_array($padding)) {
                 $attribs = $padding;
                 $padding = null;
             }
         }
     }
     $image = $this->qrCodeService->getQrCodeContent($message, $extension, $size, $padding);
     $contentType = $this->qrCodeService->generateContentType(isset($extension) ? $extension : QrCodeServiceInterface::DEFAULT_EXTENSION);
     return $this->renderer->render(self::IMG_BASE64_TEMPLATE, array('base64' => base64_encode($image), 'contentType' => $contentType, 'attribs' => $attribs));
 }
コード例 #13
0
ファイル: MailService.php プロジェクト: acelaya/zf2-acmailer
 /**
  * Renders template childrens.
  * Inspired on Zend\View\View implementation to recursively render child models
  * @param ViewModel $model
  * @see Zend\View\View::renderChildren
  */
 protected function renderChildren(ViewModel $model)
 {
     if (!$model->hasChildren()) {
         return;
     }
     /* @var ViewModel $child */
     foreach ($model as $child) {
         $capture = $child->captureTo();
         if (!empty($capture)) {
             // Recursively render children
             $this->renderChildren($child);
             $result = $this->renderer->render($child);
             if ($child->isAppend()) {
                 $oldResult = $model->{$capture};
                 $model->setVariable($capture, $oldResult . $result);
             } else {
                 $model->setVariable($capture, $result);
             }
         }
     }
 }
コード例 #14
0
 /**
  * Render
  *
  * @param string $name
  * @param array|object $params
  * @return string
  */
 public function render($name, $params = [])
 {
     $params = $this->normalizeParams($params);
     return $this->template->render($name, $params);
 }
コード例 #15
0
 /**
  * Render the widget
  */
 public function render(RendererInterface $renderer)
 {
     return $renderer->render($this->getTemplate(), $this->getVariables());
 }
コード例 #16
0
ファイル: AbstractWidget.php プロジェクト: gridguyz/core
 /**
  * Render the widget
  *
  * @param   RendererInterface   $renderer
  * @param   string              $content
  * @param   array               $params
  * @return  string
  */
 public function render(RendererInterface $renderer, $content, array $params)
 {
     return $renderer->render($this->getTemplate(), $this->getVariables(array_merge($params, array('content' => $content))));
 }
コード例 #17
0
ファイル: ProxyAbstract.php プロジェクト: gridguyz/core
 /**
  * Render view-close
  *
  * @param \Zend\View\Renderer\RendererInterface $renderer
  * @return string
  */
 public function renderClose(RendererInterface $renderer)
 {
     if (!empty(static::$viewClose)) {
         return $renderer->render(static::$viewClose, array('paragraph' => $this));
     }
     return '';
 }