/** * Return the value of the field with relative links converted to absolute urls (with placeholders parsed). * @return string */ public function AbsoluteLinks() { return HTTP::absoluteURLs($this->forTemplate()); }
/** * Make sure URI schemes are not rewritten */ public function testURISchemes() { $this->withBaseURL('http://www.silverstripe.org/', function ($test) { // mailto $test->assertEquals('<a href=\'mailto:admin@silverstripe.org\'>Email Us</a>', HTTP::absoluteURLs('<a href=\'mailto:admin@silverstripe.org\'>Email Us</a>'), 'Email links are not rewritten'); // data uri $test->assertEquals('<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38' . 'GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />', HTTP::absoluteURLs('<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH' . 'ElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />'), 'Data URI links are not rewritten'); // call $test->assertEquals('<a href="callto:12345678" />', HTTP::absoluteURLs('<a href="callto:12345678" />'), 'Call to links are not rewritten'); }); }
/** * 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 :) * * @param bool $isPlain * @return $this */ protected function parseVariables($isPlain = false) { $origState = SSViewer::config()->get('source_file_comments'); SSViewer::config()->update('source_file_comments', false); if (!$this->parseVariables_done) { $this->parseVariables_done = true; // Parse $ variables in the base parameters $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(); $candidateTemplates = [$this->ss_template, ['type' => 'email', $this->ss_template]]; $template = new SSViewer($candidateTemplates); if ($template->exists()) { $fullBody = $template->process($data); } } // Rewrite relative URLs $this->body = HTTP::absoluteURLs($fullBody); } SSViewer::config()->update('source_file_comments', $origState); return $this; }