/** * @param string $type * @return string */ function generateTemplate($type = 'html') { $entity = $this->getEntity(); $config = $this->getConfig(); $view = new \Zend\View\Renderer\PhpRenderer(); $view->setResolver($this->pathStack); if (strlen($entity->getTemplate()) > 0) { $templatePath = 'email/'; if (strpos($entity->getTemplate(), '/') === false) { $templatePath .= $entity->getTemplate(); } else { $templatePath = $entity->getTemplate(); } } else { $templatePath = 'email/default'; } if ($type == 'html') { $content = $entity->getHtml(); } else { $content = $entity->getText(); } $viewModel = new \Zend\View\Model\ViewModel(array_merge(array('content' => $content), $entity->getVars())); $viewModel->setTemplate($templatePath); $layout = new \Zend\View\Model\ViewModel(array('content' => $view->render($viewModel), 'site_name' => $config['site_name'])); $layout->setTerminal(true); $layout->setTemplate('layout/' . $type); return $view->render($layout); }
/** * Create a new view renderer * * @return \Zend\View\Renderer\PhpRenderer */ protected function _createView() { $application = \Library\Application::init('Console', true); $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager($application->getServiceManager()->get('ViewHelperManager')); return $view; }
public function getControllerPluginConfig() { return array('factories' => array('mailerZF2' => function ($sm) { $serviceLocator = $sm->getServiceLocator(); $config = $serviceLocator->get('Configuration'); if (!isset($config['email'])) { throw new \Exception('Configurazione delle mails non impostata.'); } $renderer = new \Zend\View\Renderer\PhpRenderer(); $resolver = new \Zend\View\Resolver\TemplatePathStack(); $resolver->setPaths(array(__DIR__ . '/../../../module/')); $renderer->setResolver($resolver); $controllerPlugin = new Controller\Plugin\Mailer($renderer); $mail = $config['email']['credentials']['from_mail']; $name = $config['email']['credentials']['from_name']; $controllerPlugin->setFrom($mail, $name); switch ($config['email']['transport']) { case 'smtp': $transport = new \Zend\Mail\Transport\Smtp(); $options = new \Zend\Mail\Transport\SmtpOptions(array('host' => $config['email']['smtp']['host'], 'port' => $config['email']['smtp']['port'], 'connection_class' => $config['email']['smtp']['connection_class'], 'connection_config' => $config['email']['smtp']['connection_config'])); $transport->setOptions($options); $controllerPlugin->setMailTransport($transport); break; case 'sendmail': default: $transport = new \Zend\Mail\Transport\Sendmail(); $controllerPlugin->setMailTransport($transport); break; } return $controllerPlugin; })); }
/** * Create a new view renderer * * @return \Zend\View\Renderer\PhpRenderer */ protected function _createView() { // Clone helper plugin manager to prevent state changes leaking into other tests $plugins = clone \Library\Application::getService('ViewHelperManager'); $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager($plugins); return $view; }
public function setUp() { \Zend\View\Helper\Placeholder\Registry::unsetRegistry(); $this->basePath = __DIR__ . '/_files/modules'; $renderer = new \Zend\View\Renderer\PhpRenderer(); $renderer->plugin('basePath')->setBasePath($this->basePath); $this->helper = new CtrlJsLoader(); $this->helper->setView($renderer); }
public function testFormElementHelperIntegration() { $element = new \Zend\Form\Element\Select('test'); $element->setAttribute('type', 'select_untranslated')->setValueOptions(array('Yes<b>', 'No')); $expected = <<<EOT <select name="test"><option value="0">Yes<b></option> <option value="1">No</option></select> EOT; $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager(static::$_helperManager); $helper = static::$_helperManager->get('formElement'); $helper->setView($view); $this->assertEquals($expected, $helper($element)); }
public function testFormElementHelperIntegration() { $element = new \Library\Form\Element\SelectSimple('test'); $element->setValueOptions(array('option<b>1', 'option2'))->setValue('option<b>1'); $expected = <<<EOT <select name="test"> <option selected="selected">option<b>1</option> <option>option2</option> </select> EOT; $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager(static::$_helperManager); $helper = static::$_helperManager->get('formElement'); $helper->setView($view); $this->assertEquals($expected, $helper($element)); }
/** * Get a working renderer. * * @param array $plugins Custom VuFind plug-ins to register * @param string $theme Theme directory to load from * * @return \Zend\View\Renderer\PhpRenderer */ protected function getPhpRenderer($plugins = [], $theme = 'blueprint') { $resolver = new \Zend\View\Resolver\TemplatePathStack(); // This assumes that all themes will be testing inherit directly // from root with no intermediate themes. Probably safe for most // test situations, though other scenarios are possible. $resolver->setPaths([$this->getPathForTheme('root'), $this->getPathForTheme($theme)]); $renderer = new \Zend\View\Renderer\PhpRenderer(); $renderer->setResolver($resolver); if (!empty($plugins)) { $pluginManager = $renderer->getHelperPluginManager(); foreach ($plugins as $key => $value) { $pluginManager->setService($key, $value); } } return $renderer; }
/** * Register service manager & set up Twig if * we have an environment * * @param \Pimple\Container $container */ public function register(\Pimple\Container $container) { $smConfigurator = new ServiceManagerConfigurator(); $serviceManager = $smConfigurator->createServiceManager($this->settings); $container['serviceManager'] = $serviceManager; if ($container['view'] instanceof \Slim\Views\Twig) { // Register Zend\Forms view helpers $viewHelperManager = $serviceManager->get('ViewHelperManager'); $renderer = new \Zend\View\Renderer\PhpRenderer(); $renderer->setHelperPluginManager($viewHelperManager); $environment = $container['view']->getEnvironment(); $environment->registerUndefinedFunctionCallback(function ($name) use($viewHelperManager, $renderer) { if (!$viewHelperManager->has($name)) { return false; } $callable = [$renderer->plugin($name), '__invoke']; $options = ['is_safe' => ['html']]; return new \Twig_SimpleFunction(null, $callable, $options); }); } }
<?php require './vendor/autoload.php'; $vm = new \Zend\View\Model\ViewModel(array('nom' => 'tintin')); $vm->setVariables(array('title' => 'tintin', 'description' => 'bande dessinée', 'link' => 'http://manews.fr')); $vm->setTemplate('liste'); $resol = new Zend\View\Resolver\TemplateMapResolver(array('liste' => __DIR__ . '/liste.phtml')); $rendu = new \Zend\View\Renderer\PhpRenderer(); $rendu->setResolver($resol); echo $rendu->render($vm);
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ require './vendor/autoload.php'; $vm = new \Zend\View\Model\ViewModel(); $vm->setVariables(array('nom' => 'tintin')); $vm->setTemplate('liste'); $rendu = new \Zend\View\Renderer\PhpRenderer(); echo $rendu->render($vm);
<?php require_once './autoloader.php'; use Zend\Mail\Message; use Zend\Mail\Transport; use Zend\Di\Di; use Zend\Di\Config as DiConfig; $diConfig = array('instance' => array('Zend\\Mail\\Transport\\FileOptions' => array('parameters' => array('path' => __DIR__)), 'Zend\\Mail\\Transport\\File' => array('injections' => array('Zend\\Mail\\Transport\\FileOptions')), 'Zend\\Mail\\Transport\\SmtpOptions' => array('parameters' => array('name' => 'sendgrid', 'host' => 'smtp.sendgrid.net', 'port' => 25, 'connectionClass' => 'login', 'connectionConfig' => array('username' => '*****@*****.**', 'password' => 'password'))), 'Zend\\Mail\\Message' => array('parameters' => array('headers' => 'Zend\\Mail\\Headers', 'Zend\\Mail\\Message::setTo:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setTo:name' => 'EvaEngine', 'Zend\\Mail\\Message::setFrom:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setFrom:name' => 'EvaEngine', 'setBody' => 'Zend\\View\\Renderer\\PhpRenderer::render')), 'Zend\\Mail\\Transport\\Smtp' => array('injections' => array('Zend\\Mail\\Transport\\SmtpOptions')))); $di = new Di(); $di->configure(new DiConfig($diConfig)); $transport = $di->get('Zend\\Mail\\Transport\\Smtp'); $transport = $di->get('Zend\\Mail\\Transport\\Sendmail'); $transport = $di->get('Zend\\Mail\\Transport\\File'); $message = $di->get('Zend\\Mail\\Message'); $view = new Zend\View\Renderer\PhpRenderer(); $resolver = new Zend\View\Resolver\TemplatePathStack(); $resolver->setPaths(array('mailTemplate' => __DIR__)); $view->setResolver($resolver); $viewModel = new Zend\View\Model\ViewModel(); $viewModel->setTemplate('mail/template')->setVariables(array('user' => 'AlloVince')); $message->setSubject("Zend Mail with Template")->setBody($view->render($viewModel)); $transport->send($message);
public function lostPasswordAction() { $viewModel = new ViewModel(); $form = new LostPasswordForm(); $accountFilter = new AccountFIlter(); $filter = new InputFilter(); $filter->add($accountFilter->get('email')); $form->setInputFilter($filter); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); // 找到使用者 if ($user = $em->getRepository('Base\\Entity\\User')->findOneBy(array('email' => $form->get('email')->getValue()))) { $md5 = md5(time() . $user->getUserName() . $user->getEmail()); $user->setCheckCode($md5); $em->persist($user); $em->flush(); $view = new \Zend\View\Renderer\PhpRenderer(); $resolver = new \Zend\View\Resolver\TemplateMapResolver(); $resolver->setMap(array('mailLayout' => __DIR__ . '/../../../../Application/view/layout/layout-mail.phtml', 'mailTemplate' => __DIR__ . '/../../../view/user/sign/lost-password-mail.phtml')); $view->setResolver($resolver); $uri = $this->getRequest()->getUri(); $scheme = $uri->getScheme(); $host = $uri->getHost(); $base = sprintf('%s://%s%s', $scheme, $host, $this->getRequest()->getBasePath()); $viewModel->setTemplate('mailTemplate')->setVariables(array('user' => $user, 'url' => $base)); $content = $view->render($viewModel); $viewLayout = new ViewModel(); $viewLayout->setTemplate('mailLayout')->setVariables(array('content' => $content)); $body = $view->render($viewLayout); $bodyPart = new \Zend\Mime\Message(); $bodyMessage = new \Zend\Mime\Part($body); $bodyMessage->type = 'text/html'; $bodyPart->setParts(array($bodyMessage)); $message = new Mail\Message(); $message->addTo($user->getEmail(), $user->getusername()); $message->setFrom('*****@*****.**', '系統通知信'); $message->setSubject('重設密碼通知信'); $message->setBody($bodyPart); $message->setEncoding('UTF-8'); $transport = new Mail\Transport\Sendmail(); $transport->send($message); // $viewModel->setTemplate('user/login/send-mail.phtml'); $this->flashmessenger()->addMessage($user->getEmail()); return $this->redirect()->toRoute('user/default', array('controller' => 'sign', 'action' => 'send-mail')); // return $viewModel; } else { $this->flashmessenger()->addMessage('您輸入了錯誤的帳號或電子郵件'); } } } $viewModel->setVariable('form', $form); $viewModel->setVariable('flashMessages', $this->flashMessenger()->getMessages()); return $viewModel; }
<?php return array('service_manager' => array('factories' => array('MailHtmlGenerator' => function ($sm) { $config = $sm->get('Config'); $mail = new \EmailHtmlGenerator\Service\MailHtmlGenerator(); $transport = new \Zend\Mail\Transport\Sendmail(); $mail->setTransport($transport); $viewRenderer = new \Zend\View\Renderer\PhpRenderer(); $resolver = new \Zend\View\Resolver\AggregateResolver(); $viewRenderer->setResolver($resolver); $viewsMap = new \Zend\View\Resolver\TemplatePathStack(); $viewsMap->addPaths($config['view_manager']['template_path_stack']); $resolver->attach($viewsMap); $mail->setViewRenderer($viewRenderer); return $mail; })));
/** * Create a view renderer * * A new view renderer instance is created on every call. If the state of * the renderer or a helper needs to be preserved, call this only once and * store it in a variable. * * @return \Zend\View\Renderer\PhpRenderer */ protected function _createView() { // Clone helper plugin manager to get the helpers in a fresh state. // This is important for helpers like HeadScript that store information // across invocations. These state changes must not leak into other // tests. $plugins = clone \Library\Application::getService('ViewHelperManager'); $view = new \Zend\View\Renderer\PhpRenderer(); $view->setHelperPluginManager($plugins); return $view; }
/** * Send reminders for a user. * * @param \Finna\Db\Table\Row\User $user User. * @param array $remindLoans Loans to be reminded. * * @return boolean success. */ protected function sendReminder($user, $remindLoans) { if (!$user->email || trim($user->email) == '') { $this->msg("User {$user->username} (id {$user->id})" . ' does not have an email address, bypassing due date reminders'); return false; } list($userInstitution, ) = explode(':', $user['username'], 2); if (!$this->currentInstitution || $userInstitution != $this->currentInstitution) { $templateDirs = ["{$this->baseDir}/themes/finna/templates"]; if (!($viewPath = $this->resolveViewPath($userInstitution))) { $this->err("Could not resolve view path for user {$user->username}" . " (id {$user->id})"); return false; } else { $templateDirs[] = "{$viewPath}/themes/custom/templates"; } $this->currentInstitution = $userInstitution; $this->currentViewPath = $viewPath; $resolver = new AggregateResolver(); $this->renderer->setResolver($resolver); $stack = new TemplatePathStack(['script_paths' => $templateDirs]); $resolver->attach($stack); $siteConfig = $viewPath . '/local/config/vufind/config.ini'; $this->currentSiteConfig = parse_ini_file($siteConfig, true); } $language = isset($this->currentSiteConfig['Site']['language']) ? $this->currentSiteConfig['Site']['language'] : 'fi'; $validLanguages = array_keys($this->currentSiteConfig['Languages']); if (!empty($user->finna_language) && in_array($user->finna_language, $validLanguages)) { $language = $user->finna_language; } $this->translator->addTranslationFile('ExtendedIni', null, 'default', $language)->setLocale($language); $key = $this->dueDateReminderTable->getUnsubscribeSecret($this->hmac, $user, $user->id); $params = ['id' => $user->id, 'type' => 'reminder', 'key' => $key]; $unsubscribeUrl = $this->urlHelper->__invoke('myresearch-unsubscribe') . '?' . http_build_query($params); $urlParts = explode('/', $this->currentViewPath); $urlView = array_pop($urlParts); $urlInstitution = array_pop($urlParts); $baseUrl = 'https://' . $urlInstitution . '.finna.fi'; if ($urlView != $this::DEFAULT_PATH) { $baseUrl .= "/{$urlView}"; } $params = ['loans' => $remindLoans, 'url' => $baseUrl . $this->urlHelper->__invoke('myresearch-checkedout'), 'unsubscribeUrl' => $baseUrl . $unsubscribeUrl, 'baseUrl' => $baseUrl]; $subject = $this->translator->translate('due_date_email_subject'); $message = $this->renderer->render("Email/due-date-reminder.phtml", $params); try { $to = $user->email; $from = $this->currentSiteConfig['Site']['email']; $this->serviceManager->get('VuFind\\Mailer')->send($to, $from, $subject, $message); } catch (\Exception $e) { $this->err("Failed to send due date reminders to user {$user->username} " . " (id {$user->id})"); $this->err(' ' . $e->getMessage()); return false; } foreach ($remindLoans as $loan) { $params = ['user_id' => $user->id, 'loan_id' => $loan['loanId']]; $this->dueDateReminderTable->delete($params); $dueDate = new \DateTime($loan['dueDate']); $params['due_date'] = $dueDate->format($this::DUE_DATE_FORMAT); $params['notification_date'] = gmdate($this::DUE_DATE_FORMAT, time()); $this->dueDateReminderTable->insert($params); } return true; }
<?php require './vendor/autoload.php'; $vm = new \Zend\View\Model\ViewModel(array('nom' => 'tintin')); $vm->setTemplate('liste'); $v = new Zend\View\View(); $v->addRenderingStrategy(function () { $resol = new \Zend\View\Resolver\TemplateMapResolver(array('liste' => __DIR__ . '/liste.phtml')); $rendu = new \Zend\View\Renderer\PhpRenderer(); $rendu->setResolver($resol); return $rendu; }); $v->addResponseStrategy(function ($p) { $params = $p->getParams(); $reponse = $params['response']; $rendu = $params['result']; $reponse->setContent($rendu); }); $r = new \Zend\Console\Response(); $v->setResponse($r); try { $v->render($vm); } catch (Exception $e) { echo $e->getMessage() . "\n"; } echo $v->getResponse()->getContent();
<?php use Zend\Loader\StandardAutoloader; require_once '../../../zendframework/zendframework/library/Zend/Loader/StandardAutoloader.php'; $loader = new StandardAutoloader(array('autoregister_zf' => true)); $loader->registerNamespace('Skpd\\Bootstrap\\', '../src'); $loader->register(); $view = new \Zend\View\Renderer\PhpRenderer(); $view->getHelperPluginManager()->setInvokableClass('form', 'Skpd\\Bootstrap\\Form\\View\\Helper\\Form'); $view->getHelperPluginManager()->setInvokableClass('formColor', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormColor'); $view->getHelperPluginManager()->setInvokableClass('formDateTime', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormDateTime'); $view->getHelperPluginManager()->setInvokableClass('formEmail', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormEmail'); $view->getHelperPluginManager()->setInvokableClass('formFile', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormFile'); $view->getHelperPluginManager()->setInvokableClass('formInput', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormInput'); $view->getHelperPluginManager()->setInvokableClass('formMonth', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormMonth'); $view->getHelperPluginManager()->setInvokableClass('formNumber', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormNumber'); $view->getHelperPluginManager()->setInvokableClass('formPassword', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormPassword'); $view->getHelperPluginManager()->setInvokableClass('formRow', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormRow'); $view->getHelperPluginManager()->setInvokableClass('formSelect', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormSelect'); $view->getHelperPluginManager()->setInvokableClass('formTel', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormTel'); $view->getHelperPluginManager()->setInvokableClass('formText', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormText'); $view->getHelperPluginManager()->setInvokableClass('formTextArea', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormTextarea'); $view->getHelperPluginManager()->setInvokableClass('formUrl', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormUrl'); $view->getHelperPluginManager()->setInvokableClass('formCollection', 'Skpd\\Bootstrap\\Form\\View\\Helper\\FormCollection'); $view->getHelperPluginManager()->setInvokableClass('formLabel', 'Zend\\Form\\View\\Helper\\FormLabel'); $view->getHelperPluginManager()->setInvokableClass('formElement', 'Zend\\Form\\View\\Helper\\FormElement'); $view->getHelperPluginManager()->setInvokableClass('formElementErrors', 'Zend\\Form\\View\\Helper\\FormElementErrors'); $view->getHelperPluginManager()->setInvokableClass('formCheckbox', 'Zend\\Form\\View\\Helper\\FormCheckbox'); $view->getHelperPluginManager()->setInvokableClass('formSubmit', 'Zend\\Form\\View\\Helper\\FormSubmit'); $view->getHelperPluginManager()->setInvokableClass('formButton', 'Zend\\Form\\View\\Helper\\FormButton'); $view->getHelperPluginManager()->setInvokableClass('headScript', 'Zend\\View\\Helper\\HeadScript');