public function PdfAction() { $pdf = new TCPDF('L'); $pdf->SetPrintHeader(true); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } // set font $pdf->SetFont('helvetica', '', 8); // add a page $pdf->AddPage(); //get report data into $data variable $project = $this->getServiceLocator()->get('ProjectTable'); $data = $project->getWsr(); $view = new PhpRenderer(); $resolver = new TemplateMapResolver(); //set the path of the pdf.phtml file $resolver->setMap(array('PDFTemplate' => '/var/www/html/WSRAutomation/module/Application/view/application/index/pdf.phtml')); $view->setResolver($resolver); $viewModel = new ViewModel(); $viewModel->setTemplate('PDFTemplate')->setVariables(array('projects' => $data, 'view' => 'pdf')); $html = $view->render($viewModel); $pdf->writeHTML($html, true, 0, true, 0); $pdf->Output('WsrReport.pdf', 'I'); }
public function onRoute(MvcEvent $e) { $request = $e->getRequest(); if (!$request instanceof HttpRequest) { return; } $application = $e->getApplication(); $serviceLocator = $application->getServiceManager(); // Load the configuration for maintenance mode if ($serviceLocator->has('MaintenanceConfig')) { $config = $serviceLocator->get('MaintenanceConfig'); } else { $config = new Config(); } if (!$config->isEnabled()) { // Maintenance mode is disabled. return; } // Check the white list if ($request instanceof PhpRequest) { $address = $request->getServer('REMOTE_ADDR', null); } else { $address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; } if (!empty($address)) { if (in_array($address, $config->getWhitelist())) { return; } } // Render the maintenance layout $renderer = new PhpRenderer(); if ($serviceLocator->has('ViewHelperManager')) { $renderer->setHelperPluginManager($serviceLocator->get('ViewHelperManager')); } $resolver = new TemplateMapResolver(); $resolver->add('maintenance', $config->getTemplate()); $renderer->setResolver($resolver); $content = $renderer->render('maintenance'); // Set the response $response = $e->getResponse(); if (!$response instanceof HttpResponse) { $response = new HttpResponse(); } $statusCode = $config->getStatusCode(); $response->setStatusCode($statusCode); if ($statusCode === 503 && !$response->getHeaders()->has('Retry-After')) { $retryDate = $config->getRetryAfter(); if ($retryDate instanceof DateTime) { $retryAfter = new RetryAfter(); $retryAfter->setDate($retryDate); $response->getHeaders()->addHeader($retryAfter); } } $response->setContent($content); $e->setResponse($response); // Return the response return $response; }
/** * {@inheritDoc} */ public function form(PhpRenderer $view, array $options = []) { $urlInput = new UrlElement('o:media[__index__][o:source]'); $urlInput->setOptions(['label' => $view->translate('oEmbed URL'), 'info' => $view->translate('URL for the media to embed.')]); $urlInput->setAttributes(['id' => 'media-oembed-source-__index__', 'required' => true]); return $view->formRow($urlInput); }
/** * @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; }
protected function setUp() { $this->view = new PhpRenderer(); $this->view->getHelperPluginManager()->get('basePath')->setBasePath('/'); $this->helper = new Resize(); $this->helper->setView($this->view); }
/** * {@inheritDoc} */ public function form(PhpRenderer $view, array $options = []) { $urlInput = new UrlElement('o:media[__index__][ingest_url]'); $urlInput->setOptions(['label' => $view->translate('URL'), 'info' => $view->translate('A URL to the media.')]); $urlInput->setAttributes(['id' => 'media-url-ingest-url-__index__', 'required' => true]); return $view->formRow($urlInput); }
/** * @param ContainerInterface $container * @param string $name * @param null|array $options * @return PhpRenderer */ public function __invoke(ContainerInterface $container, $name, array $options = null) { $renderer = new PhpRenderer(); $renderer->setHelperPluginManager($container->get('ViewHelperManager')); $renderer->setResolver($container->get('ViewResolver')); return $renderer; }
public function render($variables, $template) { $this->phpRenderer->setVars($variables); $result = $this->phpRenderer->render($template); $this->phpRenderer->setVars(array()); return $result; }
/** * @param ContainerInterface $container * * @return PhpRenderer */ public function __invoke(ContainerInterface $container) { $helper = $container->get(HelperPluginManager::class); $renderer = new PhpRenderer(); $renderer->setHelperPluginManager($helper); return $renderer; }
public function testFromRenderWithPassword() { $formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['status' => ['template' => 't4web-form-renderer/element/select', 'variables' => ['labels' => [1 => 'Active', 2 => 'In active', 3 => 'Deleted']]]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']]; $factory = new Factory(); $form = $factory->create($formConfig); $form->setData(['status' => 3]); $form->setMessages(['status' => ["This field is required"]]); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create"> <div class="box-body"> <div class="form-group has-error"> <label>Select</label> <select name="status" class="form-control"> <option value="1" >Active</option> <option value="2" >In active</option> <option value="3" selected>Deleted</option> </select> <p class="help-block">This field is required</p> </div> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }
public function testApplyViewHelpers() { $config = Bootstrap::getServiceManager()->get('Config'); $helperPluginManager = new HelperPluginManager(); $listener = new ViewHelperListener($this->layoutUpdater, $helperPluginManager, $config['con-layout']['view_helpers']); $mvcEvent = new \Zend\Mvc\MvcEvent(); $renderer = new PhpRenderer(); $renderer->setHelperPluginManager($helperPluginManager); $basePath = $helperPluginManager->get('basePath'); $basePath->setBasePath('/assets'); $basePathAssetPreparer = new BasePath($basePath); $listener->addAssetPreparer('headLink', $basePathAssetPreparer); /* @var $headLink HeadLink */ $headLink = $helperPluginManager->get('headLink'); /* @var $headScript HeadScript */ $headScript = $helperPluginManager->get('headScript'); /* @var $doctype \Zend\View\Helper\Doctype */ $doctype = $helperPluginManager->get('doctype'); /* @var $headTitle HeadTitle */ $headTitle = $helperPluginManager->get('headTitle'); /* @var $headMeta HeadMeta */ $headMeta = $helperPluginManager->get('headMeta'); $headMeta->setView($renderer); $listener->applyViewHelpers($mvcEvent); $expected = '<link href="/assets/css/test.css" media="screen" rel="stylesheet" type="text/css">' . PHP_EOL . '<link href="/assets/css/main.css" media="screen" rel="stylesheet" type="text/css">'; $this->assertEquals($expected, $headLink->toString()); $expected = '<script type="text/javascript" src="/js/jquery.min.js"></script>' . PHP_EOL . '<script type="text/javascript" src="/js/jquery-ui.min.js"></script>' . PHP_EOL . '<!--[if lt IE 9]><script type="text/javascript" src="/js/modernizr.js"></script><![endif]-->' . PHP_EOL . '<script type="text/javascript" src="/js/functions.js"></script>'; $this->assertEquals($expected, $headScript->toString()); $this->assertEquals('<!DOCTYPE html>', (string) $doctype); $headTitle->setSeparator(' | '); $expected = '<title>First | My Title | Another Title</title>'; $this->assertEquals($expected, $headTitle->toString()); $expected = '<meta charset="utf8">' . PHP_EOL . '<meta name="description" content="My description">' . PHP_EOL . '<meta name="keywords" content="keyword1, keyword2, keyword3">'; $this->assertEquals($expected, $headMeta->toString()); }
/** * Support function to display spelling suggestions. * * @param string $msg HTML to display at the top of * the spelling section. * @param \VuFind\Search\Base\Results $results Results object * @param \Zend\View\Renderer\PhpRenderer $view View renderer object * * @return string */ public function renderSpellingSuggestions($msg, $results, $view) { $spellingSuggestions = $results->getSpellingSuggestions(); if (empty($spellingSuggestions)) { return ''; } $html = '<div class="' . $this->getContainerClass() . '">'; $html .= $msg; foreach ($spellingSuggestions as $term => $details) { $html .= '<br/>' . $view->escapeHtml($term) . ' » '; $i = 0; foreach ($details['suggestions'] as $word => $data) { if ($i++ > 0) { $html .= ', '; } $html .= '<a href="' . $results->getUrlQuery()->replaceTerm($term, $data['new_term']) . '">' . $view->escapeHtml($word) . '</a>'; if (isset($data['expand_term']) && !empty($data['expand_term'])) { $url = $results->getUrlQuery()->replaceTerm($term, $data['expand_term']); $html .= $this->renderExpandLink($url, $view); } } } $html .= '</div>'; return $html; }
public function testFromRenderWithCheckbox() { $formConfig = ['template' => 't4web-form-renderer/element/form', 'children' => ['terms' => ['template' => 't4web-form-renderer/element/checkbox', 'variables' => ['label' => 'Terms']]], 'variables' => ['action' => '/admin/news/create', 'cancelLink' => '/admin/list']]; $factory = new Factory(); $form = $factory->create($formConfig); $form->setData(['terms' => 1]); $form->setMessages(['terms' => ["You must read and check"]]); $rawHtml = $this->renderer->render($form); $this->assertEquals(preg_replace('/\\s+/', ' ', '<form method="post" action="/admin/news/create"> <div class="box-body"> <div class="form-group has-error"> <div class="checkbox"> <label> <input type="checkbox" name="terms" value="1"> Terms </label> </div> <p class="help-block">You must read and check</p> </div> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" id="submit-btn">Submit</button> <a class="btn btn-default" href="/admin/list">Cancel</a> </div> </form>'), preg_replace('/\\s+/', ' ', $rawHtml)); }
public function renderPost(Renderer $renderer) { $coreformsjs = $renderer->basepath('/Core/js/core.forms.js'); $javaScript = <<<JS \$(document).ready(function() { console.log('attached yk.forms.done to ', \$('form')); \$('form').on('yk.forms.done', function(event, data) { //if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {} if (typeof data != 'undefined' && typeof data['data'] != 'undefined') { if (typeof data['data']['jobvalid'] != 'undefined' && data['data']['jobvalid'] === true) { \$('#job_incomplete').hide(); \$('#finalize_jobentry').show(); } else { \$('#job_incomplete').show(); \$('#finalize_jobentry').hide(); } } \$('#job_errormessages').empty(); if (typeof data['data']['errorMessage'] != 'undefined') { \$('#job_errormessages').append(data['data']['errorMessage']); } console.debug('job-form-inline', event, data); }); }); JS; $renderer->headScript()->appendScript($javaScript); return parent::renderPost($renderer); }
/** * Prepares the environment before running a test * */ protected function setUp() { $cwd = __DIR__; // read navigation config $this->_files = $cwd . '/_files'; $config = ConfigFactory::fromFile($this->_files . '/navigation.xml', true); // setup containers from config $this->_nav1 = new Navigation($config->get('nav_test1')); $this->_nav2 = new Navigation($config->get('nav_test2')); // setup view $view = new PhpRenderer(); $view->resolver()->addPath($cwd . '/_files/mvc/views'); // create helper $this->_helper = new $this->_helperName(); $this->_helper->setView($view); // set nav1 in helper as default $this->_helper->setContainer($this->_nav1); // setup service manager $smConfig = array('modules' => array(), 'module_listener_options' => array('config_cache_enabled' => false, 'cache_dir' => 'data/cache', 'module_paths' => array(), 'extra_config' => array('service_manager' => array('factories' => array('Config' => function () use($config) { return array('navigation' => array('default' => $config->get('nav_test1'))); }))))); $sm = $this->serviceManager = new ServiceManager(new ServiceManagerConfig()); $sm->setService('ApplicationConfig', $smConfig); $sm->get('ModuleManager')->loadModules(); $sm->get('Application')->bootstrap(); $sm->setFactory('Navigation', 'Zend\\Navigation\\Service\\DefaultNavigationFactory'); $sm->setService('nav1', $this->_nav1); $sm->setService('nav2', $this->_nav2); $app = $this->serviceManager->get('Application'); $app->getMvcEvent()->setRouteMatch(new RouteMatch(array('controller' => 'post', 'action' => 'view', 'id' => '1337'))); }
/** * @outputBuffering disabled */ public function testCanRenderFieldsets() { $this->expectOutputRegex('/<form(.*)<fieldset(.*)<\\/fieldset>(.*)<fieldset(.*)<\\/fieldset>(.*)<\\/form>/'); $form = new NetsensiaForm(); $form->addHidden('test1', 'testvalue'); $hidden = new Element\Hidden('asdasd'); $hidden->setValue('123'); $form->add($hidden); $element1 = new Text('testelement1'); $element1->setLabel('Test Element'); $element1->setAttribute('icon', 'pencil'); $element2 = new Text('testelement2'); $element2->setLabel('Test Element 2'); $element2->setAttribute('icon', 'pencil'); $fieldset1 = new Fieldset('testfieldset1'); $fieldset1->add($element1); $fieldset2 = new Fieldset('testfieldset2'); $fieldset2->add($element2); $form->add($fieldset1); $form->add($fieldset2); $helpers = new HelperPluginManager(); $helpers->setService('formElement', new FormElement()); $view = new PhpRenderer(); $view->setHelperPluginManager($helpers); $viewHelper = new BootstrapForm(); $viewHelper->setView($view); $viewHelper($form, 'testform', '/'); }
public function testCanSetResolverInstance() { $resolver = new TemplatePathStack(); $this->renderer->setResolver($resolver); $this->assertSame($resolver, $this->renderer->resolver()); $this->assertSame($this->phpRenderer->resolver(), $this->renderer->resolver()); }
public function setUp() { $this->wrapperHelper = new Wrapper(); $view = new PhpRenderer(); $view->setHelperPluginManager(new HelperPluginManager()); $this->wrapperHelper->setView($view); }
public function render(PhpRenderer $view, SitePageBlockRepresentation $block) { $attachments = $block->attachments(); if (!$attachments) { return ''; } $html = ''; foreach ($attachments as $attachment) { $html .= '<div>'; $item = $attachment->item(); if ($item) { $html .= '<h2>' . $item->link($item->displayTitle()) . '</h2>'; $media = $attachment->media(); if (!$media) { $media = $item->primaryMedia(); } if ($media) { $thumbnailType = $this->getData($block->data(), 'thumbnail_type', 'square'); $html .= '<h3>' . $media->link($media->displayTitle()) . '</h3>'; $html .= '<img src="' . $view->escapeHtml($media->thumbnailUrl($thumbnailType)) . '">'; } } $caption = $attachment->caption(); if ($caption) { $html .= '<p>' . $caption . '</p>'; } $html .= '</div>'; } return $html; }
public function testCsrfHtmlDoctype() { $object = new FormCsrf(); $view = new View(); $view->doctype()->setDoctype(strtoupper("HTML5")); $object->setView($view); $this->assertRegExp('/[^\\/]>$/', $object->__invoke()); }
public function setUp() { $this->transport = new MockTransport(); $config = (include __DIR__ . '/../../config/module.config.php'); $renderer = new PhpRenderer(); $renderer->setResolver(new TemplatePathStack($config['view_manager']['template_path_stack'])); $this->mailService = new MailService(new Message(), $this->transport, $renderer); }
public function render(PhpRenderer $view, SitePageBlockRepresentation $block) { $html = ''; $html .= '<div class="navigation-block">'; $html .= $view->navigation('Zend\\Navigation\\Site')->menu()->renderSubMenu(); $html .= '</div>'; return $html; }
/** * Test if doctype is HTML */ public function testGravatarHtmlDoctype() { $object = new Gravatar(); $view = new View(); $view->doctype()->setDoctype(strtoupper("HTML5")); $object->setView($view); $this->assertRegExp('/[^\\/]>$/', $this->helper->__invoke('*****@*****.**')->__toString()); }
/** * {@inheritdoc} */ protected function setUp() { $this->helper = new SnippetHelper(); $view = new PhpRenderer(); $view->resolver()->addPath(__DIR__ . '/../../../view'); $view->resolver()->addPath(__DIR__ . '/_files/modules'); $this->helper->setView($view); }
public function setUp() { $config = (include __DIR__ . '/../../../config/module.config.php'); $renderer = new PhpRenderer(); $renderer->setResolver(new TemplateMapResolver($config['view_manager']['template_map'])); $router = TreeRouteStack::factory($config['router']); $this->helper = new QrCodeHelper($renderer, $router, new QrCodeServiceMock('foobar')); }
public function testRaisesExceptionIfViewModelHelperHasNoRoot() { $renderer = new PhpRenderer(); $viewModelHelper = $renderer->plugin('view_model'); $helper = $renderer->plugin('layout'); $this->setExpectedException('Zend\\View\\Exception\\RuntimeException', 'view model'); $helper->setTemplate('foo/bar'); }
/** * {@inheritDoc} */ public function form(PhpRenderer $view, array $options = []) { $fileInput = new File('file[__index__]'); $fileInput->setOptions(['label' => $view->translate('Upload File')]); $fileInput->setAttributes(['id' => 'media-file-input-__index__']); $field = $view->formRow($fileInput); return $field . '<input type="hidden" name="o:media[__index__][file_index]" value="__index__">'; }
/** * @return PhpRenderer */ public function getTestRenderer() { $resolver = new TemplatePathStack(); $resolver->addPath(__DIR__ . '/../views'); $renderer = new PhpRenderer(); $renderer->setResolver($resolver); return $renderer; }
public function setUp() { $view = new View(); $base = str_replace('/', DIRECTORY_SEPARATOR, '/../_templates'); $view->resolver()->addPath(__DIR__ . $base); $view->vars()->setStrictVars(true); $this->view = $view; }
/** * @param string|string[] $dependencies */ public function __invoke($dependencies = array()) { $this->config->addDependencies($dependencies); if (!$this->libraryIncluded) { $this->view->inlineScript()->appendScript($this->config)->appendFile($this->library); $this->libraryIncluded = true; } }