/** * Load all the template variables into the internal variables, including * the template into body. Called before send() or debugSend() * $isPlain=true will cause the template to be ignored, otherwise the GenericEmail template will be used * and it won't be plain email :) * * This function is updated to rewrite urls in a safely manner and inline css. * It will also changed the requirements backend to avoid requiring stuff in the html. */ protected function parseVariables($isPlain = false) { $origState = Config::inst()->get('SSViewer', 'source_file_comments'); Config::inst()->update('SSViewer', 'source_file_comments', false); // Workaround to avoid clutter in our rendered html $backend = Requirements::backend(); Requirements::set_backend(new MandrillRequirementsBackend()); if (!$this->parseVariables_done) { $this->parseVariables_done = true; if (!$this->original_body) { $this->original_body = $this->body; } // Parse $ variables in the base parameters $data = $this->templateData(); // Process a .SS template file $fullBody = $this->original_body; if ($this->parse_body) { try { $viewer = new SSViewer_FromString($fullBody); $fullBody = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } // Also parse the email title try { $viewer = new SSViewer_FromString($this->subject); $this->subject = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } if ($this->callout) { try { $viewer = new SSViewer_FromString($this->callout); $this->callout = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } } if ($this->sidebar) { try { $viewer = new SSViewer_FromString($this->sidebar); $this->sidebar = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } } } if ($this->ss_template && !$isPlain) { // Requery data so that updated versions of To, From, Subject, etc are included $data = $this->templateData(); $template = new SSViewer($this->ss_template); if ($template->exists()) { // Make sure we included the parsed body into layout $data->setField('Body', $fullBody); try { $fullBody = $template->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } } } // Rewrite relative URLs $this->body = self::rewriteURLs($fullBody); } Config::inst()->update('SSViewer', 'source_file_comments', $origState); Requirements::set_backend($backend); return $this; }
/** * Load all the template variables into the internal variables, including * the template into body. Called before send() or debugSend() * $isPlain=true will cause the template to be ignored, otherwise the GenericEmail template will be used * and it won't be plain email :) */ protected function parseVariables($isPlain = false) { $origState = Config::inst()->get('SSViewer', 'source_file_comments'); Config::inst()->update('SSViewer', 'source_file_comments', false); if (!$this->parseVariables_done) { $this->parseVariables_done = true; // Parse $ variables in the base parameters $data = $this->templateData(); // Process a .SS template file $fullBody = $this->body; if ($this->ss_template && !$isPlain) { // Requery data so that updated versions of To, From, Subject, etc are included $data = $this->templateData(); $template = new SSViewer($this->ss_template); if ($template->exists()) { $fullBody = $template->process($data); } } // Rewrite relative URLs $this->body = HTTP::absoluteURLs($fullBody); } Config::inst()->update('SSViewer', 'source_file_comments', $origState); return $this; }
/** * Load all the template variables into the internal variables, including * the template into body. Called before send() or debugSend() * $isPlain=true will cause the template to be ignored, otherwise the GenericEmail template will be used * and it won't be plain email :) */ protected function parseVariables($isPlain = false) { if(!$this->parseVariables_done) { $this->parseVariables_done = true; // Parse $ variables in the base parameters $data = $this->templateData(); foreach(array('from','to','subject','body', 'plaintext_body', 'cc', 'bcc') as $param) { $template = SSViewer::fromString($this->$param); $this->$param = $template->process($data); } // Process a .SS template file $fullBody = $this->body; if($this->ss_template && !$isPlain) { // Requery data so that updated versions of To, From, Subject, etc are included $data = $this->templateData(); $template = new SSViewer($this->ss_template); if($template->exists()) { $fullBody = $template->process($data); } } // Rewrite relative URLs $this->body = HTTP::absoluteURLs($fullBody); } }