Ejemplo n.º 1
0
 /**
  * Instance of construct
  * 
  * @param string $layout
  * @param array $options
  */
 public function __construct($layout = 'email', array $options = array())
 {
     $this->frontController = \Zend_Controller_Front::getInstance();
     $resources = $this->frontController->getParam('bootstrap')->getOption('resources');
     if (isset($options['layout'])) {
         $this->layout = new \Zend_Layout($options['layout']);
     } elseif (isset($resources['layout'])) {
         $this->layout = new \Zend_Layout($resources['layout']);
     } else {
         $this->layout = new \Zend_Layout();
     }
     if (isset($options['view'])) {
         $this->layout->setView(new \Zend_View($options['view']));
     } elseif (isset($resources['view'])) {
         $this->layout->setView(new \Zend_View($resources['view']));
     } else {
         $this->layout->setView(new \Zend_View());
     }
     $scriptPath = APPLICATION_PATH . self::EMAIL_PATH;
     if (null !== $this->frontController->getModuleDirectory()) {
         $scriptPath = $this->frontController->getModuleDirectory() . self::EMAIL_PATH;
     }
     $this->layout->setLayout($layout);
     $this->setScriptPath($scriptPath);
 }
Ejemplo n.º 2
0
 /**
  * Tạo Object Layout cho Email
  */
 private function generateLayout()
 {
     $layout = new Zend_Layout();
     $layout->setLayoutPath(APPLICATION_PATH . 'modules/admin/views/scripts/email');
     $layout->setLayout('layout');
     return $layout;
 }
Ejemplo n.º 3
0
 /**
  * get Zend_Layout instance
  * @param $name
  * 
  * @return Zend_Layout
  */
 public static function getLayout($name)
 {
     if (!is_null($name)) {
         self::$_layout->setLayout($name);
     }
     return self::$_layout;
 }
Ejemplo n.º 4
0
 private function __construct()
 {
     // setup file error logging
     $file_writer = new Logger_Errorlog();
     if (Config::get_optional("DEBUG_LOG") == false) {
         $file_writer->addFilter(Zend_Log::INFO);
     }
     $log = new Zend_Log();
     $log->addWriter($file_writer);
     // setup email error logging
     if (Config::get_optional("log_to_email") == true) {
         $mail = new Zend_Mail();
         $mail->setFrom(Config::get_mandatory('log_email_from'));
         $mail->addTo(Config::get_mandatory('log_email_to'));
         // setup email template
         $layout = new Zend_Layout();
         $layout->setLayoutPath(DOCUMENT_ROOT . Config::get_mandatory("log_email_template"));
         $layout->setLayout('error-logger');
         $layout_formatter = new Zend_Log_Formatter_Simple('<li>.' . Zend_Log_Formatter_Simple::DEFAULT_FORMAT . '</li>');
         // Use default HTML layout.
         $email_writer = new Zend_Log_Writer_Mail($mail, $layout);
         $email_writer->setLayoutFormatter($layout_formatter);
         $email_writer->setSubjectPrependText(Config::get_mandatory('log_email_subject_prepend'));
         $email_writer->addFilter(Zend_Log::ERR);
         $log->addWriter($email_writer);
     }
     self::$logger = $log;
 }
Ejemplo n.º 5
0
Archivo: Email.php Proyecto: ud223/yj
 public function sendEmail($template, $to, $subject, $params = array())
 {
     try {
         $config = array('auth' => 'Login', 'port' => $this->_bootstrap_options['mail']['port'], 'ssl' => 'ssl', 'username' => $this->_bootstrap_options['mail']['username'], 'password' => $this->_bootstrap_options['mail']['password']);
         $tr = new Zend_Mail_Transport_Smtp($this->_bootstrap_options['mail']['server'], $config);
         Zend_Mail::setDefaultTransport($tr);
         $mail = new Zend_Mail('UTF-8');
         $layout = new Zend_Layout();
         $layout->setLayoutPath($this->_bootstrap_options['mail']['layout']);
         $layout->setLayout('email');
         $view = $layout->getView();
         $view->domain_url = $this->_bootstrap_options['site']['domainurl'];
         $view = new Zend_View();
         $view->params = $params;
         $view->setScriptPath($this->_bootstrap_options['mail']['view_script']);
         $layout->content = $view->render($template . '.phtml');
         $content = $layout->render();
         $mail->setBodyText(preg_replace('/<[^>]+>/', '', $content));
         $mail->setBodyHtml($content);
         $mail->setFrom($this->_bootstrap_options['mail']['from'], $this->_bootstrap_options['mail']['from_name']);
         $mail->addTo($to);
         $mail->setSubject($subject);
         $mail->send();
     } catch (Exception $e) {
         // 这里要完善
     }
     return true;
 }
Ejemplo n.º 6
0
 public function setViewBody($script, $params = array())
 {
     $layout = new Zend_Layout(array('layoutPath' => $this->_getLayoutPath()));
     $layout->setLayout('email');
     $view = new Zend_View();
     $view->setScriptPath($this->_getViewPath() . '/email');
     foreach ($params as $k => $param) {
         $view->assign($k, $param);
     }
     $layout->content = $view->render($script . '.phtml');
     //$layout->content = $msg;
     $html = $layout->render();
     $this->setBodyHtml($html);
 }
Ejemplo n.º 7
0
 /**
  * Initialize Logging
  *
  */
 protected function _initLogging()
 {
     $this->bootstrap('log');
     Zend_Registry::set('log', $log = $this->getResource('log'));
     $mail = new Zend_Mail();
     $config = Zend_Registry::get('config');
     $mail->addTo($config->core->debugMailTo);
     $layout = new Zend_Layout();
     $layout->setLayout('errormail');
     $writer = new Zend_Log_Writer_Mail($mail, $layout);
     $writer->setSubjectPrependText('CORE Error');
     $writer->addFilter(Zend_Log::CRIT);
     #$log->addWriter($writer);
 }
Ejemplo n.º 8
0
 public function setBodyView($script, $params = array())
 {
     $layout = new Zend_Layout(array('layoutPath' => APPLICATION_PATH . '/views/layouts'));
     $layout->setLayout('email');
     $view = new Zend_View();
     $view->setScriptPath(APPLICATION_PATH . '/views/email');
     foreach ($params as $key => $value) {
         $view->assign($key, $value);
     }
     $layout->content = $view->render($script . '.phtml');
     $html = $layout->render();
     $this->setBodyHtml($html);
     return $this;
 }
Ejemplo n.º 9
0
 public function postDispatch()
 {
     $layouts = array_reverse($this->_layouts);
     $mvcLayout = Zend_Layout::getMvcInstance();
     $mvcContentKey = $mvcLayout->getContentKey();
     $content = $this->getResponse()->getBody();
     $view = $this->_cloneView();
     $layout = new Zend_Layout(array('layoutPath' => $mvcLayout->getLayoutPath(), 'viewSuffix' => $mvcLayout->getViewSuffix()));
     $layout->setView($view);
     foreach ($layouts as $layoutName) {
         $layout->setLayout($layoutName);
         $layout->{$mvcContentKey} = $this->getResponse()->getBody();
         $this->getResponse()->setBody($layout->render());
     }
 }
Ejemplo n.º 10
0
 public function __invoke($message)
 {
     $layout = new Zend_Layout();
     // Установка пути к скриптам макета:
     $layout->setLayoutPath(APPLICATION_PATH . '/views/scripts/layouts');
     $layout->setLayout('inner');
     $view = new Zend_View();
     $view->setBasePath(APPLICATION_PATH . '/views/');
     $view->error_message = $message;
     // установка переменных:
     $layout->content = $view->render('/exeption/user.phtml');
     echo $layout->render();
     //echo $message;
     die;
 }
Ejemplo n.º 11
0
 public function setBodyView($script, $params = array())
 {
     $layout = new Zend_Layout(array('layoutPath' => APPLICATION_PATH . '/layouts'));
     //вибрати шаблон email.phtml
     $layout->setLayout('email');
     $view = new Zend_View();
     $view->setScriptPath(APPLICATION_PATH . '/views/email');
     foreach ($params as $key => $value) {
         //Метод assign() дает возможность устанавливать значения
         //из массива или объекта "партиями".
         $view->assign($key, $value);
     }
     $layout->content = $view->render($script . '.phtml');
     $html = $layout->render();
     $this->setBodyHtml($html);
     return $this;
 }
Ejemplo n.º 12
0
 /**
  * Switch layout based on the given condition
  *
  * @param string $ruleName
  */
 protected function _switchLayout($ruleName)
 {
     if (!$this->_layout) {
         $layout = Zend_Layout::getMvcInstance();
         if (!$layout) {
             $layout = Zend_Layout::startMvc();
         }
         $this->_layout = $layout;
     }
     if (!$this->_defaultLayout) {
         $this->_defaultLayout = $this->_layout->getLayout();
     }
     if (array_key_exists($ruleName, $this->_layouts)) {
         $this->_layout->setLayout($this->_layouts[$ruleName]);
     } else {
         $this->_layout->setLayout($this->_defaultLayout);
     }
 }
Ejemplo n.º 13
0
 /**
  * Build the txt part of the email using the provided scripts
  *
  * @return void
  */
 private function _buildTextBody()
 {
     $viewContent = '';
     if ($this->getTxtView()) {
         $viewContent = $this->view->render($this->getTxtView());
         if (!$this->getTxtLayout()) {
             // no layout, render only the view
             $this->setBodyText($viewContent);
         }
     }
     if ($this->getTxtLayout()) {
         $this->_layout->setLayout($this->getTxtLayout());
         $this->_layout->setView($this->view);
         // assign rendered view to the layout
         $this->_layout->assign('content', $viewContent);
         // render the layout
         $this->setBodyText($this->_layout->render($this->getTxtLayout()));
     }
 }
Ejemplo n.º 14
0
 /**
  * Return the layout for the email log
  *
  * @return Zend_Layout
  */
 protected function getLayout()
 {
     $layout = new Zend_Layout(dirname(__FILE__));
     $layout->setLayout('log-email');
     return $layout;
 }
Ejemplo n.º 15
0
 public function testLayoutWithViewBasePath()
 {
     $layout = new Zend_Layout(array('viewBasePath' => dirname(__FILE__) . '/_files/layouts-basepath/'));
     $this->assertEquals('layout inside basePath', $layout->render());
     $layout->setLayout('layout2');
     $this->assertEquals('foobar-helper-output', $layout->render());
 }
Ejemplo n.º 16
0
 protected function _prepareLayout()
 {
     $this->_oLayout = Zend_Layout::startMvc();
     $this->_oLayout->setLayout($this->_sLayout);
 }
 protected function _getMailLayout()
 {
     $layout = new Zend_Layout();
     $layout->setLayoutPath(ENGINEBLOCK_FOLDER_APPLICATION . 'layouts/scripts');
     $layout->setLayout('error-mail');
     return $layout;
 }
Ejemplo n.º 18
0
 /**
  * @return void
  */
 public function testSetLayoutEnablesLayouts()
 {
     $layout = new Zend_Layout();
     $layout->disableLayout();
     $this->assertFalse($layout->isEnabled());
     $layout->setLayout('foo');
     $this->assertTrue($layout->isEnabled());
 }
Ejemplo n.º 19
0
 public function setBaseRender($key, $template = null, $view = null)
 {
     if ($key instanceof Zend_View) {
         $template = $key->getTemplate();
         $view = $key;
     } else {
         $view = is_null($view) ? $this->getView() : $this->_getView($view);
         $view->setTemplate($template);
     }
     if (preg_match('/.phtml$/', $template)) {
         $this->disableInflector();
     }
     parent::setLayout($template);
     $this->_base_render = $view;
     $this->_is_loaded = true;
     return $view;
 }
Ejemplo n.º 20
0
 /**
  * @group ZF-5891
  */
 public function testSetLayoutWithDisabledFlag()
 {
     $layout = new Zend_Layout();
     $layout->disableLayout();
     $layout->setLayout('foo', false);
     $this->assertEquals('foo', $layout->getLayout());
     $this->assertFalse($layout->isEnabled());
 }
 protected function _bootstrapLayout()
 {
     $layout = new Zend_Layout();
     // Set a layout script path:
     $layout->setLayoutPath(ENGINEBLOCK_FOLDER_APPLICATION . 'layouts/scripts/');
     // Defaults
     $defaultsConfig = $this->_application->getConfiguration()->defaults;
     $layout->title = $defaultsConfig->title;
     $layout->header = $defaultsConfig->header;
     // choose a different layout script:
     $layout->setLayout($defaultsConfig->layout);
     $this->_application->setLayout($layout);
 }
Ejemplo n.º 22
0
 /**
  * Set a layout for this HTML file
  * 
  * @param  string $layoutFile
  * @return Geves_Mail
  */
 public function setLayout($layoutFile)
 {
     $this->_layout = new Zend_Layout();
     $this->_layout->setLayout($layoutFile);
     return $this;
 }
Ejemplo n.º 23
0
 /**
  * Render mail content using a view and template 
  * 
  * @param string $template
  * @param array $substitutions
  * @param array $placeholders
  * @param string $mode
  * @param string $layout
  * @param string $layoutPath
  */
 public function getMailContent($template, $substitutions, $placeholders = array(), $mode = 'html', $layout = null, $layoutPath = null)
 {
     // Create the return variable
     $return = '';
     // Create a view renderer
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $view = clone $viewRenderer->view;
     // Create a layout object and set it to app_path/emails/layouts
     if ($layoutPath === null || $layoutPath == '') {
         $layoutPath = PUBLIC_PATH . $view->templateUrl('') . 'email' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
     }
     // Create the layout object
     $layoutObject = new Zend_Layout($layoutPath);
     // Add the script path to the view that overrules the default path
     $application = $this->getFrontController()->getParam('application');
     $module = $this->getRequest()->getModuleName();
     $scriptPath = $view->layout()->getViewScriptPath() . '/views/' . $application . '/modules/' . $module . '/';
     if (!in_array($scriptPath, $view->getScriptPaths())) {
         $view->addScriptPath($scriptPath);
     }
     // Add the default email folder for the layout/template
     $view->addScriptPath(PUBLIC_PATH . $view->templateUrl('') . 'email' . DIRECTORY_SEPARATOR . 'views');
     // Assign all substitutions (e.g. view variables) to the view view
     foreach ($substitutions as $key => $sub) {
         $view->{$key} = $sub;
     }
     // Replace all placeholders
     if (is_array($placeholders)) {
         foreach ($placeholders as $key => $sub) {
         }
     }
     // Set the view object to the layout object
     $layoutObject->setView($view);
     // Initialize a default layout
     if ($layout === null || $layout == '') {
         $layout = 'default';
     }
     switch ($mode) {
         case 'html':
             // Render html version of template & assign to $return
             $layoutObject->content = $view->render($template . '.html.phtml');
             // Set the layout
             $layoutObject->setLayout('' . $layout . '.html');
             // Render the layout output
             $return = $layoutObject->render();
             // Assimilate the stylesheet in the html
             $stylesheet = $layoutPath . $layout . '.css';
             if (file_exists($stylesheet)) {
                 $stylesheetContent = file_get_contents($stylesheet);
                 $test = new CSSToInlineStyles($return, $stylesheetContent);
                 $return = $test->convert(true);
             }
             break;
         case 'text':
             // Render text version of template & assign to $return
             $layoutObject->content = $view->render($template . '.text.phtml');
             // Set the layout
             $layoutObject->setLayout('' . $layout . '.text');
             // Render the layout output
             $return = $layoutObject->render();
             break;
     }
     // Replace the placeholders in the content
     $return = $this->_replacePlaceholders($return, $placeholders);
     // all done, return output
     return $return;
 }