Esempio n. 1
0
 /**
  * Render the contents using the current layout and template.
  * Overridden to support plugin templates
  *
  * @param   string  $content Content to render
  * @return  array   Email ready to be sent
  */
 public function _render($content)
 {
     $msg = array();
     $content = implode("\n", $content);
     if ($this->sendAs === 'both') {
         $htmlContent = $content;
         if (!empty($this->attachments)) {
             $msg[] = '--' . $this->__boundary;
             $msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
             $msg[] = '';
         }
         $msg[] = '--alt-' . $this->__boundary;
         $msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
         $msg[] = 'Content-Transfer-Encoding: 7bit';
         $msg[] = '';
         $content = $this->_view->element('email' . DS . 'text' . DS . $this->template, array('content' => $content, 'plugin' => 'Referee'), true);
         $this->_view->layoutPath = 'email' . DS . 'text';
         $content = explode("\n", $this->textMessage = str_replace(array("\r\n", "\r"), "\n", $this->_view->renderLayout($content)));
         $msg = array_merge($msg, $content);
         $msg[] = '';
         $msg[] = '--alt-' . $this->__boundary;
         $msg[] = 'Content-Type: text/html; charset=' . $this->charset;
         $msg[] = 'Content-Transfer-Encoding: 7bit';
         $msg[] = '';
         $htmlContent = $this->_view->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent, 'plugin' => 'Referee'), true);
         $this->_view->layoutPath = 'email' . DS . 'html';
         $htmlContent = explode("\n", $this->htmlMessage = str_replace(array("\r\n", "\r"), "\n", $this->_view->renderLayout($htmlContent)));
         $msg = array_merge($msg, $htmlContent);
         $msg[] = '';
         $msg[] = '--alt-' . $this->__boundary . '--';
         $msg[] = '';
         return $msg;
     }
     if (!empty($this->attachments)) {
         if ($this->sendAs === 'html') {
             $msg[] = '';
             $msg[] = '--' . $this->__boundary;
             $msg[] = 'Content-Type: text/html; charset=' . $this->charset;
             $msg[] = 'Content-Transfer-Encoding: 7bit';
             $msg[] = '';
         } else {
             $msg[] = '--' . $this->__boundary;
             $msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
             $msg[] = 'Content-Transfer-Encoding: 7bit';
             $msg[] = '';
         }
     }
     $content = $this->_view->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content, 'plugin' => 'Referee'), true);
     $this->_view->layoutPath = 'email' . DS . $this->sendAs;
     $content = explode("\n", $rendered = str_replace(array("\r\n", "\r"), "\n", $this->_view->renderLayout($content)));
     if ($this->sendAs === 'html') {
         $this->htmlMessage = $rendered;
     } else {
         $this->textMessage = $rendered;
     }
     $msg = array_merge($msg, $content);
     return $msg;
 }
Esempio n. 2
0
 /**
  * Renders the layout and includes the css stylesheet for inlining the styles
  *
  * @param string $content_for_layout
  * @param string $layout
  * @return string
  */
 public function renderLayout($content_for_layout, $layout = null)
 {
     $output = parent::renderLayout($content_for_layout, $layout);
     $css = file_get_contents(CSS . 'email.css');
     $inliner = new CssToInlineStyles($output, $css);
     return $inliner->convert();
 }
Esempio n. 3
0
 public function renderLayout($content_for_layout, $layout = null)
 {
     $paths = $this->parseSubLayoutsPath($layout);
     foreach ($paths as $path) {
         $content_for_layout = parent::renderLayout($content_for_layout, $path);
     }
     return $content_for_layout;
 }
Esempio n. 4
0
 static function deliver($template, $options = array())
 {
     $options = Set::merge(array('vars' => array(), 'mail' => array('to' => array(), 'from' => Configure::read('App.emails.noReply'), 'charset' => 'utf8', 'sendAs' => 'text', 'subject' => '', 'template' => $template, 'layout' => 'email', 'attachments' => array()), 'store' => false), $options);
     if (!empty($options['mail']['subject'])) {
         $options['mail']['subject'] = strip_tags($options['mail']['subject']);
     }
     $delivery = Configure::read('App.emailDeliveryMethod');
     if (!empty($delivery) && !isset($options['mail']['delivery'])) {
         $options['mail']['delivery'] = $delivery;
     }
     if (isset($options['mail']['delivery']) && $options['mail']['delivery'] == 'smtp') {
         $options['mail']['smtpOptions'] = Configure::read('App.smtpOptions');
     }
     if (Common::isDevelopment()) {
         $options['mail']['delivery'] = 'debug';
     }
     App::import('Core', 'Controller');
     $Email = Common::getComponent('Email');
     Common::setProperties($Email, $options['mail']);
     if (!isset($Email->Controller)) {
         App::import('Core', 'Router');
         $Email->Controller = new AppController();
     }
     $Email->Controller->set($options['vars']);
     if ($options['store']) {
         $hash = sha1(json_encode($options));
         $folder = substr($hash, 0, 2);
         $file = substr($hash, 2) . '.html';
         $url = '/emails/' . $folder . '/' . $file;
         $path = APP . 'webroot' . $url;
         if (!is_dir(dirname($path))) {
             @mkdir(dirname($path));
         }
         $url = Router::url($url, true);
         $Email->Controller->set('emailUrl', $url);
         $View = new View($Email->Controller, false);
         $View->layout = $Email->layout;
         $View->layoutPath = 'email' . DS . 'html';
         $html = $View->element('email' . DS . 'html' . DS . $options['mail']['template'], array('content' => null), true);
         $html = $View->renderLayout($html);
         file_put_contents($path, $html);
     }
     if (!isset($Email->Controller->Session)) {
         $Email->Controller->Session = Common::getComponent('Session');
     }
     $result = $Email->send();
     if (Common::isDevelopment() && Configure::read('App.email_debug')) {
         Common::debugEmail();
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * not_found
  *
  * @return void
  * @author Armando Sosa
  */
 function not_found()
 {
     header("HTTP/1.0 404 Not Found");
     View::output('<h2>Sorry, there\'s nothing here</h2>');
     View::set('pageTitle', '404 not found');
     View::renderLayout();
 }
Esempio n. 6
0
 public function __construct($type = "", $details = array())
 {
     $view = new View();
     $filename = Inflector::underscore($type);
     $viewFile = App::path("View", "errors/{$filename}.htm");
     if (!$viewFile) {
         $viewFile = App::path("View", "errors/missing_error.htm");
         $details = array("error" => $type);
     }
     $content = $view->renderView($viewFile, array("details" => $details));
     echo $view->renderLayout($content, "error", "htm");
     $this->stop();
 }
 /**
  * Extend Layout Render for Nice Indention
  *
  * @param string $content_for_layout
  * @return string 
  */
 function renderLayout($content_for_layout)
 {
     if ($content_for_layout) {
         $whitespace = CakeHamlParser::INDENT * ($this->Haml->indentBy - 1);
         $content_for_layout = $this->Haml->indentContent($content_for_layout, $this->Haml->indentBy);
         $content_for_layout = "\n" . $content_for_layout . "\n";
         $content_for_layout .= str_repeat(" ", $whitespace);
     }
     return parent::renderLayout($content_for_layout);
 }
Esempio n. 8
0
 /**
  * Renders a layout. Returns output from _render(). Returns false on error.
  * Several variables are created for use in layout.
  *	title_for_layout - contains page title
  *	content_for_layout - contains rendered view file
  *	scripts_for_layout - contains scripts added to header
  *  cakeDebug - if debug is on, cake debug information is added.
  *
  * @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
  * @return mixed Rendered output, or false on error
  */
 function renderLayout($content_for_layout, $layout = null)
 {
     unset($this->viewVars['cakeDebug']);
     // we have better debugging tools than this
     return parent::renderLayout($content_for_layout, $layout);
 }
 function _addFlash($flashMessage, $layout = 'flash_info', $params = array(), $key = 'flash')
 {
     $out = $this->Session->read('Message.' . $key);
     $view = new View($this);
     $view->base = $this->base;
     $view->webroot = $this->webroot;
     $view->here = $this->here;
     $view->params = $this->params;
     $view->action = $this->action;
     $view->data = $this->data;
     $view->plugin = $this->plugin;
     $view->helpers = array('Html');
     $view->layout = $layout;
     $view->pageTitle = '';
     $view->viewVars = $view->_viewVars = $params;
     $out .= $view->renderLayout($flashMessage);
     //$this->Session->write('Message.' . $key, $out);
 }
Esempio n. 10
0
 /**
  * Renders the notification template
  *
  * @param string $template The template to render
  * @return string Rendered content
  */
 protected function _render($template)
 {
     $View = new View($this->Controller, false);
     $View->layout = 'notification';
     list($plugin, $template) = pluginSplit($template);
     $content = $View->element('notification' . DS . $template, compact('plugin'), true);
     $content = $View->renderLayout($content);
     return $content;
 }