Exemple #1
0
 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;
     }));
 }
Exemple #2
0
 /**
  * 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;
 }
<?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);
Exemple #4
0
 public function getResolverPaths()
 {
     $pathResolver = new \Zend\View\Resolver\TemplatePathStack();
     $arrayPathResolver = array($this->moduleName . '_layout' => $this->getPathLayout(), $this->moduleName . '_template' => $this->getPathViews() . DS . 'templates', $this->moduleName . '_helpers' => $this->getPathViews() . DS . 'helpers');
     return $pathResolver->setPaths($arrayPathResolver);
 }
Exemple #5
0
 /**
  * Initialize the theme by selecting a theme using the adapters and updating the view resolver
  */
 public function init()
 {
     //if already initialized then return
     if ($this->currentTheme) {
         return true;
     }
     //find the current theme that should be used
     $theme = $this->selectCurrentTheme();
     if (!$theme) {
         return false;
     }
     //get theme configuration
     $config = $this->getThemeConfig($theme);
     if (!$config) {
         return false;
     }
     $viewResolver = $this->serviceManager->get('ViewResolver');
     $themeResolver = new \Zend\View\Resolver\AggregateResolver();
     if (isset($config['template_map'])) {
         $viewResolverMap = $this->serviceManager->get('ViewTemplateMapResolver');
         $viewResolverMap->add($config['template_map']);
         $mapResolver = new \Zend\View\Resolver\TemplateMapResolver($config['template_map']);
         $themeResolver->attach($mapResolver);
     }
     if (isset($config['template_path_stack'])) {
         $viewResolverPathStack = $this->serviceManager->get('ViewTemplatePathStack');
         $viewResolverPathStack->addPaths($config['template_path_stack']);
         $pathResolver = new \Zend\View\Resolver\TemplatePathStack(array('script_paths' => $config['template_path_stack']));
         $defaultPathStack = $this->serviceManager->get('ViewTemplatePathStack');
         $pathResolver->setDefaultSuffix($defaultPathStack->getDefaultSuffix());
         $themeResolver->attach($pathResolver);
     }
     $viewResolver->attach($themeResolver, 100);
     return true;
 }
 /**
  * On dispatch loop startup layout change is happens
  *
  * @param \Zend\Mvc\MvcEvent $event
  * @return \ZlyTemplater\Model\Mapper\Layout
  */
 public function getLayout(\Zend\Mvc\MvcEvent $event)
 {
     if ($this->_layout instanceof \ZlyTemplater\Model\Mapper\Layout) {
         return $this->_layout;
     }
     $request = $event->getRouteMatch();
     $locator = $event->getTarget()->getLocator();
     if ($locator->instanceManager()->hasAlias('sysmap-service')) {
         $mapIdentifiers = $locator->get('sysmap-service')->getCurentlyActiveItems($request);
         /**
          * Get current layout from config
          */
         if (empty($mapIdentifiers)) {
             $currentLayout = $this->model->getDefaultLayout();
         } else {
             $currentLayout = $this->model->getCurrentLayout($mapIdentifiers);
         }
         if (!empty($currentLayout)) {
             $this->_layout = $currentLayout;
             $this->attachWidgets($event, $currentLayout->getWidgets());
         }
         /* @var $view \Zend\View\Renderer\PhpRenderer */
         $view = $event->getTarget()->getLocator()->get('view');
         $layoutName = '';
     }
     if (!empty($currentLayout)) {
         $themeDirectory = $this->getThemePath($currentLayout);
         $layoutPath = $this->getLayoutPath($currentLayout);
         $customResolver = new \Zend\View\Resolver\TemplatePathStack();
         $customResolver->addPath($layoutPath);
         $view->resolver()->attach($customResolver, 99);
         $this->themePath = str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', realpath($themeDirectory)));
         $layoutName = $currentLayout->getName() . '.phtml';
         $layoutFile = realpath($layoutPath . DIRECTORY_SEPARATOR . $layoutName);
     } else {
         $currentLayout = new \ZlyTemplater\Model\Mapper\Layout();
     }
     if (!empty($layoutFile)) {
         $currentLayout->setPath($layoutName);
     } else {
         $currentLayout->setPath($this->getConfig()->layout->default);
     }
     return $currentLayout;
 }
Exemple #7
0
 /**
  * Set module view root path to module/{module name}/view
  * Reset layout by config->module_namespace_layout_map
  * 
  * @return ViewHelperLoader
  */
 public function onDispatch(MvcEvent $e)
 {
     $routeParams = $e->getRouteMatch()->getParams();
     if (false === isset($routeParams['module']) || !$routeParams['module']) {
         return false;
     }
     $controller = $e->getTarget();
     if (!$controller instanceof \Zend\Mvc\Controller\AbstractActionController && !$controller instanceof \Zend\Mvc\Controller\AbstractRestfulController) {
         //Event should trigger after route matched and found controller
         throw new \Zend\Mvc\Exception\RuntimeException(printf('%s should be only trigger on mvc dispatch event', __METHOD__));
     }
     $object = new \ReflectionObject($controller);
     $controllerFullPath = $object->getFileName();
     $controllerClassname = $object->getName();
     $classRootPath = substr($controllerFullPath, 0, 0 - strlen($controllerClassname . '.php'));
     $moduleRootPath = $classRootPath . '..';
     $this->viewRootPath = $moduleRootPath . DIRECTORY_SEPARATOR . 'view';
     $moduleNamespace = isset($routeParams['moduleNamespace']) ? $routeParams['moduleNamespace'] : '';
     if ($moduleNamespace && $routeParams['moduleNamespace'] && $routeParams['moduleNamespace'] != $routeParams['module']) {
         $this->viewRootPath .= DIRECTORY_SEPARATOR . '_' . strtolower($routeParams['moduleNamespace']);
     }
     if ($moduleNamespace && isset($this->config['module_namespace_layout_map']) && !isset($this->config['layout']) && isset($this->config['module_namespace_layout_map'][ucfirst($moduleNamespace)])) {
         $viewModel = $this->getViewModel();
         $template = $viewModel->getTemplate();
         if ($template == 'layout/layout') {
             $controller->layout('layout/' . $moduleNamespace);
         }
     }
     $templatePathStack = new \Zend\View\Resolver\TemplatePathStack();
     //All path defined in config will be clear here
     $templatePathStack->setPaths(array($this->viewRootPath));
     $this->resolver->attach($templatePathStack);
 }
<?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;
})));
Exemple #9
0
 /**
  * Renders a template fragment within a variable scope distinct from the
  * calling View object.
  *
  * If no arguments are passed, returns the helper instance.
  *
  * If the $model is an array, it is passed to the view object's assign()
  * method.
  *
  * If the $model is an object, it first checks to see if the object
  * implements a 'toArray' method; if so, it passes the result of that
  * method to to the view object's assign() method. Otherwise, the result of
  * get_object_vars() is passed.
  *
  * @param  string $name Name of view script
  * @param  array $model Variables to populate in the view
  * @return string|Partial
  * @throws Exception\RuntimeException
  */
 public function __invoke($moduleName = null, $name = null, $model = null)
 {
     if (0 == func_num_args()) {
         return $this;
     }
     $view = $this->cloneView();
     if (isset($this->partialCounter)) {
         $view->partialCounter = $this->partialCounter;
     }
     $module = $this->serviceLocator->getServiceLocator()->get('modulemanager')->getModule($moduleName);
     if (!$module) {
         return '';
     }
     $object = new \ReflectionObject($module);
     $modulePath = dirname($object->getFileName());
     if (!$modulePath) {
         return '';
     }
     $modulePath .= DIRECTORY_SEPARATOR . 'view';
     $resolver = new \Zend\View\Resolver\TemplatePathStack();
     $resolver->addPaths(array($modulePath));
     $view->setResolver($resolver);
     if (!empty($model)) {
         if (is_array($model)) {
             $view->vars()->assign($model);
         } elseif (is_object($model)) {
             if (null !== ($objectKey = $this->getObjectKey())) {
                 $view->vars()->offsetSet($objectKey, $model);
             } elseif (method_exists($model, 'toArray')) {
                 $view->vars()->assign($model->toArray());
             } else {
                 $view->vars()->assign(get_object_vars($model));
             }
         }
     }
     return $view->render($name);
 }
Exemple #10
0
 /**
  * Set the Layout based on themes-scheme
  */
 public function setLayout(MvcEvent $e)
 {
     $app = $e->getParam('application');
     $sm = $app->getServiceManager();
     $config = $sm->get('dxapp_module_options');
     $mobileDetect = $sm->get('dxMobileDetect');
     $viewModel = $e->getViewModel();
     $template = 'layout/layout';
     //$viewModel->getTemplate();
     $frontendThemex = $config->getFrontendTheme();
     $templateMaps = $config->getTemplateMaps();
     $frontendThemes = $config->getFrontendThemes();
     //array('dxdefault');
     $viewResolver = $sm->get('ViewResolver');
     $viewThemeResolver = new \Zend\View\Resolver\AggregateResolver();
     $templateMapResolver = new \Zend\View\Resolver\TemplateMapResolver();
     $pathResolver = new \Zend\View\Resolver\TemplatePathStack();
     $asseticConfiguration = array();
     if (!in_array($frontendThemex, $frontendThemes)) {
         $frontendThemes[] = $frontendThemex;
     }
     foreach ($frontendThemes as $frontendTheme) {
         if (isset($templateMaps['front'][$frontendTheme]['view_manager']['template_map'])) {
             $templateMapResolver->add($templateMaps['front'][$frontendTheme]['view_manager']['template_map']);
         }
         if (isset($templateMaps['front'][$frontendTheme]['view_manager']['template_path_stack'])) {
             $pathResolver->addPaths($templateMaps['front'][$frontendTheme]['view_manager']['template_path_stack']);
             $defaultPathStack = $sm->get('ViewTemplatePathStack');
             $pathResolver->setDefaultSuffix($defaultPathStack->getDefaultSuffix());
             $viewThemeResolver->attach($pathResolver);
         }
         if (isset($templateMaps['front'][$frontendTheme]['assetic_configuration'])) {
             $asseticConfiguration = \Dxapp\Utility\ArrayManager::merge($asseticConfiguration, $templateMaps['front'][$frontendTheme]['assetic_configuration']);
         }
     }
     $viewThemeResolver->attach($templateMapResolver);
     $viewResolver->attach($viewThemeResolver, 100);
     if (!empty($asseticConfiguration)) {
         $as = $sm->get('dxThemeAssets');
         $response = $e->getResponse();
         if (!$response) {
             $response = new Response();
             $e->setResponse($response);
         }
         $router = $e->getRouteMatch();
         $as->setThemeAssets($asseticConfiguration);
         if ($router) {
             $as->setRouteName($router->getMatchedRouteName());
             $as->setControllerName($router->getParam('controller'));
             $as->setActionName($router->getParam('action'));
         }
         $as->renderThemeAssets();
         $as->initLoadedModules($this->getLoadedModules());
         $as->setupRenderer($sm->get('ViewRenderer'));
     }
     $section = $config->getApplicationSection();
     if ($section == 'admin') {
         if (FALSE === strpos($template, 'admin-')) {
             $template = str_replace('/', '/admin-', $template);
         }
     }
     $viewModel->setTemplate($template);
 }