public function updateNewsletterEmail(NewsletterEmail $email)
 {
     $newsletter = $email->Newsletter();
     if ($newsletter->ContentSource != 'page' || !$newsletter->SourcePageID) {
         return;
     }
     $page = $newsletter->SourcePage();
     $response = Director::test($page->RelativeLink());
     $body = $this->emogrify($response->getBody());
     $body = str_replace('xmlns="http://www.w3.org/1999/xhtml"', '', HTTP::absoluteURLs($body));
     $re = '/\\.src\\s*=' . str_replace('/', '\\/', Director::absoluteBaseURL()) . '/';
     $body = preg_replace($re, '.src =', $body);
     // undo the fudging that happens to keywords
     $body = preg_replace('/"[^"]*%7B%24(\\w+)%7D/', '"{\\$$1}', $body);
     $email->setBody(DBField::create('HTMLText', $body));
 }
 /**
  * turns an html document into a formatted html document
  * using the emogrify method.
  * @param $html
  * @return String HTML
  */
 public static function emogrify_html($html)
 {
     //get required files
     $baseFolder = Director::baseFolder();
     if (!class_exists('\\Pelago\\Emogrifier')) {
         require_once $baseFolder . '/ecommerce/thirdparty/Emogrifier.php';
     }
     $cssFileLocation = Director::baseFolder() . "/" . EcommerceConfig::get("Order_Email", "css_file_location");
     $cssFileHandler = fopen($cssFileLocation, 'r');
     $css = fread($cssFileHandler, filesize($cssFileLocation));
     fclose($cssFileHandler);
     $emogrifier = new \Pelago\Emogrifier($html, $css);
     $html = $emogrifier->emogrify();
     //make links absolute!
     $html = HTTP::absoluteURLs($html);
     return $html;
 }
 /**
  * 	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');
     });
 }
Esempio n. 4
0
 function AbsoluteLinks()
 {
     return HTTP::absoluteURLs($this->value);
 }
 public function process()
 {
     $fromTime = $this->since ? $this->since : 0;
     $members = $this->members;
     $nextId = array_shift($members);
     $this->members = $members;
     $member = Member::get()->byID($nextId);
     $microBlogService = $this->microBlogService;
     // if we don't have a 'since' time, we need to only scan from 'now' onwards, to prevent _every_
     // post from being collected
     if (!$fromTime) {
         $fromTime = time();
     }
     $since = date('Y-m-d 00:00:00', $fromTime);
     if ($member && $member->ID) {
         $this->transactionManager->run(function () use($microBlogService, $since, $member) {
             $posts = $microBlogService->globalFeed(array('ParentID' => 0, 'ThreadOwnerID:not' => $member->ID, 'Created:GreaterThan' => $since), $orderBy = 'ID DESC', $since = null, $number = 10, $markViewed = false);
             if (!count($posts)) {
                 return;
             }
             $content = SSViewer::execute_template('DigestEmail', ArrayData::create(array('Posts' => $posts, 'Member' => $member)));
             $content = HTTP::absoluteURLs($content);
             $config = SiteConfig::current_site_config();
             $mail = new Email();
             $mail->setTo($member->Email);
             $mail->setBody($content);
             $mail->setSubject($config->Title . ' digest');
             if ($config->FromEmail) {
                 $mail->setFrom($config->FromEmail);
             }
             $mail->send();
         }, $member);
     }
     $this->currentStep++;
     if (count($members) == 0) {
         if (!$this->sendTime) {
             $this->sendTime = '23:55:00';
         }
         $nextTime = $this->type == 'weekly' ? '+1 week' : '+1 day';
         $nextDate = date('Y-m-d ' . $this->sendTime, strtotime($nextTime));
         $nextJob = new MicroPostDigestJob(time(), $this->type, $this->groupId, $this->sendTime);
         singleton('QueuedJobService')->queueJob($nextJob, $nextDate);
         $this->isComplete = true;
     }
 }
 /**
  * display a text message after order creation
  *
  * @param Order $orderObj the order object
  * 
  * @return void
  *
  * @author Sascha Koehler <*****@*****.**>
  * @copyright 2011 pixeltricks GmbH
  * @since 06.01.2011
  */
 public function processPaymentConfirmationText($orderObj)
 {
     parent::processPaymentConfirmationText($orderObj);
     $variables = array('SilvercartOrder' => $orderObj);
     $templateVariables = new ArrayData($variables);
     switch ($this->PaymentChannel) {
         case 'invoice':
             $textTemplate = new SSViewer_FromString($this->InvoiceInfo);
             break;
         case 'prepayment':
         default:
             $textTemplate = new SSViewer_FromString($this->TextBankAccountInfo);
     }
     $text = HTTP::absoluteURLs($textTemplate->process($templateVariables));
     return $text;
 }
Esempio n. 7
0
 /**
  * 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;
 }
Esempio n. 8
0
 /**
  * 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());
 }
 function render()
 {
     if (!($templateName = $this->RenderTemplate)) {
         $templateName = 'SimpleNewsletterTemplate';
     }
     // Block stylesheets and JS that are not required (email templates should have inline CSS/JS)
     Requirements::clear();
     // Create recipient with some test data
     $recipient = new Recipient(Recipient::$test_data);
     $newsletterEmail = new NewsletterEmail($this, $recipient, true);
     return HTTP::absoluteURLs($newsletterEmail->getData()->renderWith($templateName));
 }
 public function digest()
 {
     if (!Permission::check('ADMIN')) {
         return $this->httpError(403);
     }
     $posts = $this->microBlogService->globalFeed(array('Created:GreaterThan' => date('Y-m-d 00:00:00', strtotime('-1 month'))), $orderBy = 'ID DESC', $since = null, $number = 10, $markViewed = false);
     if (!count($posts)) {
         return;
     }
     $content = SSViewer::execute_template('DigestEmail', ArrayData::create(array('Posts' => $posts, 'Member' => Member::currentUser())));
     $content = HTTP::absoluteURLs($content);
     echo $content;
 }
 /**
  * Overloaded from {@link Widget->Content()}
  * to allow for controller/form linking.
  *
  * @return string HTML
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 20.06.2013
  */
 public function Content()
 {
     $renderData = array('Controller' => $this);
     $template = new SSViewer_FromString($this->getField('FreeText'));
     $freeText = HTTP::absoluteURLs($template->process(new ArrayData($renderData)));
     $data = new ArrayData(array('FreeText' => $freeText, 'LinkText' => $this->LinkText, 'Link' => $this->Link));
     return $this->customise($data)->renderWith($this->widget->class);
 }
 /**
  * sends email to defined address
  *
  * @param string $identifier  identifier for email template
  * @param string $to          recipients email address
  * @param array  $variables   array with template variables that can be called in the template
  * @param array  $attachments absolute filename to an attachment file
  *
  * @return bool
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 16.06.2014
  */
 public static function send($identifier, $to, $variables = array(), $attachments = null)
 {
     $mailObj = SilvercartShopEmail::get()->filter('Identifier', $identifier)->first();
     if (!$mailObj) {
         return false;
     }
     $emailText = trim($mailObj->EmailText);
     if (is_null($emailText) || empty($emailText)) {
         return false;
     }
     $emailSubject = trim($mailObj->Subject);
     if (is_null($emailSubject) || empty($emailSubject)) {
         return false;
     }
     if (!is_array($variables)) {
         $variables = array();
     }
     $templateVariables = new ArrayData($variables);
     $emailTextTemplate = new SSViewer_FromString($mailObj->EmailText);
     $emailText = HTTP::absoluteURLs($emailTextTemplate->process($templateVariables));
     $emailSubjectTemplate = new SSViewer_FromString($mailObj->Subject);
     $emailSubject = HTTP::absoluteURLs($emailSubjectTemplate->process($templateVariables));
     $email = new Email(SilvercartConfig::EmailSender(), $to, $emailSubject, $mailObj->EmailText);
     $email->setTemplate('SilvercartShopEmail');
     $email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
     self::attachFiles($email, $attachments);
     $email->send();
     if (SilvercartConfig::GlobalEmailRecipient() != '') {
         $email = new Email(SilvercartConfig::EmailSender(), SilvercartConfig::GlobalEmailRecipient(), $emailSubject, $mailObj->EmailText);
         $email->setTemplate('SilvercartShopEmail');
         $email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
         $email->send();
     }
     //Send the email to additional standard receipients from the n:m
     //relation AdditionalReceipients;
     //Email address is validated.
     if ($mailObj->AdditionalReceipients()->exists()) {
         foreach ($mailObj->AdditionalReceipients() as $additionalReceipient) {
             if ($additionalReceipient->getEmailAddressWithName() && Email::validEmailAddress($additionalReceipient->Email)) {
                 $to = $additionalReceipient->getEmailAddressWithName();
             } elseif ($additionalReceipient->getEmailAddress() && Email::validEmailAddress($additionalReceipient->Email)) {
                 $to = $additionalReceipient->getEmailAddress();
             } else {
                 continue;
             }
             $email = new Email(SilvercartConfig::EmailSender(), $to, $emailSubject, $mailObj->EmailText);
             $email->setTemplate('SilvercartShopEmail');
             $email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
             self::attachFiles($email, $attachments);
             $email->send();
         }
     }
 }
Esempio n. 13
0
	/**
	 * 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);
		}
	}
Esempio n. 14
0
 /**
  * Return the value of the field with relative links converted to absolute urls.
  * @return string
  */
 public function AbsoluteLinks()
 {
     return HTTP::absoluteURLs($this->RAW());
 }
 /**
  * Preview a {@link Newsletter} draft.
  *
  * @param SS_HTTPRequest $request Request parameters
  */
 public function preview($request)
 {
     $newsletterID = (int) $request->param('ID');
     $newsletter = DataObject::get_by_id('Newsletter', $newsletterID);
     $templateName = $newsletter && $newsletter->Parent()->Template ? $newsletter->Parent()->Template : 'GenericEmail';
     // Block stylesheets and JS that are not required (email templates should have inline CSS/JS)
     Requirements::clear();
     $email = new NewsletterEmail($newsletter);
     return HTTP::absoluteURLs($email->getData()->renderWith($templateName));
 }