diff --git a/src/Abstracts/EmailAbstract.php b/src/Abstracts/EmailAbstract.php index b904e0ee070ef576ed47b7c5335e2463350a8764..5aba38c803aee18da6a6a7df37bbbf178e5f4e80 100644 --- a/src/Abstracts/EmailAbstract.php +++ b/src/Abstracts/EmailAbstract.php @@ -11,8 +11,9 @@ abstract class EmailAbstract implements EmailInterface { */ private $renderer; - public function __construct( Renderer $renderer ) { - $this->renderer = $renderer; + public function __construct( Renderer $renderer, array $recipients ) { + $this->renderer = $renderer; + $this->recipients = $recipients; } /** @@ -37,6 +38,10 @@ abstract class EmailAbstract implements EmailInterface { * @return string */ public function get_subject(): string { + if ( ! $this->subject ) { + throw new \Exception( 'Empty email subject' ); + } + return ''; } @@ -55,7 +60,7 @@ abstract class EmailAbstract implements EmailInterface { * @return string[] */ public function get_recipients(): array { - return []; + return $this->recipients; } /** @@ -91,6 +96,10 @@ abstract class EmailAbstract implements EmailInterface { * @return string */ public function get_content(): string { + if ( ! $this->content ) { + throw new \Exception( 'Empty email subject' ); + } + return ''; } diff --git a/src/Abstracts/EmailInterface.php b/src/Abstracts/EmailInterface.php index 4e0fc286e3902d823bbbc586c57a141b82ac55c0..8439a4472b69b22af289730473a349ea92c62e52 100644 --- a/src/Abstracts/EmailInterface.php +++ b/src/Abstracts/EmailInterface.php @@ -67,11 +67,4 @@ interface EmailInterface { */ public function get_content(): string; - /** - * Send email. - * - * @return void - */ - public function send(): void; - } diff --git a/src/Integration.php b/src/Integration.php new file mode 100644 index 0000000000000000000000000000000000000000..087e0fe892708d83ca74624d9bdc1fdff7388be6 --- /dev/null +++ b/src/Integration.php @@ -0,0 +1,31 @@ +<?php + +namespace WPDesk\Library\WPEmail; + +use WPDesk\Library\WPEmail\Emails\AdminEmail; +use WPDesk\Library\WPEmail\Emails\Email; +use WPDesk\Library\WPEmail\Emails\EmailSender; +use WPDesk\Persistence\Adapter\WordPress\WordpressOptionsContainer; +use WPDesk\Persistence\Adapter\WordPress\WordpressTransientContainer; +use WPDesk\View\Renderer\SimplePhpRenderer; +use WPDesk\View\Resolver\ChainResolver; +use WPDesk\View\Resolver\DirResolver; +use WPDesk\View\Resolver\WPThemeResolver; + +class Integration { + + public function __construct() { + $chain_resolver = new ChainResolver(); + $chain_resolver->appendResolver( new WPThemeResolver( 'email_templates' ) ); + $chain_resolver->appendResolver( new DirResolver( __DIR__ . '/templates' ) ); + $renderer = new SimplePhpRenderer( $chain_resolver ); + + $email_sender = new EmailSender( 'email@mojastron.pl', 'Moj sklep' ); + $email = new Email( $renderer, [] ); + + $email_sender->add_email( $email ); + $email_sender->send(); + + } + +} diff --git a/src/Parser/HTMLDecorator.php b/src/Parser/HTMLDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..dd6bf5643386b7b71e4ccf715cecd38e42278af3 --- /dev/null +++ b/src/Parser/HTMLDecorator.php @@ -0,0 +1,39 @@ +<?php + +namespace WPDesk\Library\WPEmail\Parser; + +class HTMLDecorator { + + public static function style_inline( $content ) { + if ( in_array( $this->get_content_type(), array( 'text/html', 'multipart/alternative' ), true ) ) { + ob_start(); + wc_get_template( 'emails/email-styles.php' ); + $css = apply_filters( 'woocommerce_email_styles', ob_get_clean(), $this ); + + $css_inliner_class = \Pelago\Emogrifier\CssInliner::class; + + if ( $this->supports_emogrifier() && class_exists( $css_inliner_class ) ) { + try { + $css_inliner = \Pelago\Emogrifier\CssInliner::fromHtml( $content )->inlineCss( $css ); + + do_action( 'woocommerce_emogrifier', $css_inliner, $this ); + + $dom_document = $css_inliner->getDomDocument(); + + HtmlPruner::fromDomDocument( $dom_document )->removeElementsWithDisplayNone(); + $content = CssToAttributeConverter::fromDomDocument( $dom_document ) + ->convertCssToVisualAttributes() + ->render(); + } catch ( Exception $e ) { + $logger = wc_get_logger(); + $logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) ); + } + } else { + $content = '<style type="text/css">' . $css . '</style>' . $content; + } + } + + return $content; + } + +} diff --git a/src/tempates/html/default.php b/src/tempates/html/default.php new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/tempates/plain/default.php b/src/tempates/plain/default.php new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391