Completed
Push — develop ( d8eab8...c1cebe )
by Paul
01:57
created
src/Image.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	protected $postmeta;
13 13
 	protected $utility;
14 14
 
15
-	public function __construct( PostMeta $postmeta, Utility $utility )
15
+	public function __construct(PostMeta $postmeta, Utility $utility)
16 16
 	{
17 17
 		$this->postmeta = $postmeta;
18 18
 		$this->utility  = $utility;
@@ -23,43 +23,43 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @return self
25 25
 	 */
26
-	public function get( $attachment )
26
+	public function get($attachment)
27 27
 	{
28
-		$attachment = $this->normalize( $attachment );
29
-		if( $attachment && $thumbnail = wp_get_attachment_image_src( $attachment, 'thumbnail' )) {
30
-			$medium = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'medium' ), $thumbnail );
31
-			$large = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'large' ), $medium );
28
+		$attachment = $this->normalize($attachment);
29
+		if ($attachment && $thumbnail = wp_get_attachment_image_src($attachment, 'thumbnail')) {
30
+			$medium = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'medium'), $thumbnail);
31
+			$large = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'large'), $medium);
32 32
 
33 33
 			$this->image = (object) [
34
-				'alt'       => wp_strip_all_tags( get_post_meta( $attachment, '_wp_attachment_image_alt', true ), true ),
35
-				'caption'   => wp_get_attachment_caption( $attachment ),
36
-				'copyright' => wp_strip_all_tags( get_post_meta( $attachment, '_copyright', true ), true ),
34
+				'alt'       => wp_strip_all_tags(get_post_meta($attachment, '_wp_attachment_image_alt', true), true),
35
+				'caption'   => wp_get_attachment_caption($attachment),
36
+				'copyright' => wp_strip_all_tags(get_post_meta($attachment, '_copyright', true), true),
37 37
 				'ID'        => $attachment,
38 38
 				'large'     => $large,
39 39
 				'medium'    => $medium,
40
-				'permalink' => get_attachment_link( $attachment ),
41
-				'thumbnail' => $this->normalizeSrc( $thumbnail ),
40
+				'permalink' => get_attachment_link($attachment),
41
+				'thumbnail' => $this->normalizeSrc($thumbnail),
42 42
 			];
43 43
 		}
44 44
 		return $this;
45 45
 	}
46 46
 
47
-	public function render( $size = 'large' )
47
+	public function render($size = 'large')
48 48
 	{
49
-		if( $this->image ) {
50
-			return wp_get_attachment_image( $this->image->ID, $size );
49
+		if ($this->image) {
50
+			return wp_get_attachment_image($this->image->ID, $size);
51 51
 		}
52 52
 	}
53 53
 
54
-	protected function normalize( $attachmentId )
54
+	protected function normalize($attachmentId)
55 55
 	{
56
-		if( !filter_var( $attachmentId, FILTER_VALIDATE_INT )) {
57
-			$attachmentId = $this->postmeta->get( $attachmentId );
56
+		if (!filter_var($attachmentId, FILTER_VALIDATE_INT)) {
57
+			$attachmentId = $this->postmeta->get($attachmentId);
58 58
 		}
59 59
 
60
-		$attachment = get_post( $attachmentId );
60
+		$attachment = get_post($attachmentId);
61 61
 
62
-		if( is_null( $attachment ) || $attachment->post_type != 'attachment' )return;
62
+		if (is_null($attachment) || $attachment->post_type != 'attachment')return;
63 63
 
64 64
 		return $attachment->ID;
65 65
 	}
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return array
71 71
 	 */
72
-	protected function normalizeSrc( array $image, $fallback = false )
72
+	protected function normalizeSrc(array $image, $fallback = false)
73 73
 	{
74
-		if( is_array( $fallback ) && count( array_diff( $image, $fallback )) < 2 ) {
74
+		if (is_array($fallback) && count(array_diff($image, $fallback)) < 2) {
75 75
 			$image = $fallback;
76 76
 		}
77 77
 		return [
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@
 block discarded – undo
59 59
 
60 60
 		$attachment = get_post( $attachmentId );
61 61
 
62
-		if( is_null( $attachment ) || $attachment->post_type != 'attachment' )return;
62
+		if( is_null( $attachment ) || $attachment->post_type != 'attachment' ) {
63
+			return;
64
+		}
63 65
 
64 66
 		return $attachment->ID;
65 67
 	}
Please login to merge, or discard this patch.
src/Video.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	protected $theme;
21 21
 	protected $utility;
22 22
 
23
-	public function __construct( Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility )
23
+	public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility)
24 24
 	{
25 25
 		$this->image    = $image;
26 26
 		$this->oembed   = $oembed;
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 		$this->utility  = $utility;
30 30
 	}
31 31
 
32
-	public function get( $args = [] )
32
+	public function get($args = [])
33 33
 	{
34
-		$args = $this->normalize( $args );
35
-		$embed = $this->oembed->request( $args['url'], $args['player'] );
36
-		if( isset( $embed->type ) && $embed->type == 'video' ) {
34
+		$args = $this->normalize($args);
35
+		$embed = $this->oembed->request($args['url'], $args['player']);
36
+		if (isset($embed->type) && $embed->type == 'video') {
37 37
 			$this->video = $embed;
38 38
 		}
39 39
 		return $this;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
 	public function render()
43 43
 	{
44
-		if( !isset( $this->video->html ))return;
44
+		if (!isset($this->video->html))return;
45 45
 		return sprintf(
46 46
 			'<div class="video embed">%s%s</div>',
47 47
 			$this->renderScreenshot(),
@@ -59,15 +59,15 @@  discard block
 block discarded – undo
59 59
 				'<a href="%s" class="video-play-btn">%s</a>' .
60 60
 			'</div>',
61 61
 			$this->args['url'],
62
-			$this->theme->svg( 'play.svg' )
62
+			$this->theme->svg('play.svg')
63 63
 		);
64 64
 	}
65 65
 
66 66
 	public function renderScreenshot()
67 67
 	{
68
-		if( $this->args['image']
69
-			&& in_array( strtolower( $this->video->provider_name ), $this->supported )) {
70
-			return sprintf( '%s<div class="video-poster" style="background-image: url(%s)">%s</div>',
68
+		if ($this->args['image']
69
+			&& in_array(strtolower($this->video->provider_name), $this->supported)) {
70
+			return sprintf('%s<div class="video-poster" style="background-image: url(%s)">%s</div>',
71 71
 				$this->renderSpinner(),
72 72
 				$this->args['image'],
73 73
 				$this->renderPlayButton()
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
 			'<div class="video-spinner">' .
82 82
 				'<div class="spinner"><div class="spinner-dots">%s</div></div>' .
83 83
 			'</div>',
84
-			implode( '', array_fill( 0, 8, '<div class="spinner-dot"></div>' ))
84
+			implode('', array_fill(0, 8, '<div class="spinner-dot"></div>'))
85 85
 		);
86 86
 	}
87 87
 
88
-	protected function setImage( $image )
88
+	protected function setImage($image)
89 89
 	{
90
-		$image = $this->image->get( $image )->image;
91
-		$this->args['image'] = isset( $image->large )
90
+		$image = $this->image->get($image)->image;
91
+		$this->args['image'] = isset($image->large)
92 92
 			? $image->large['url']
93 93
 			: null;
94 94
 	}
95 95
 
96
-	protected function setUrl( $url )
96
+	protected function setUrl($url)
97 97
 	{
98
-		$this->args['url'] = !filter_var( $url, FILTER_VALIDATE_URL )
99
-			? $this->postmeta->get( $url )
98
+		$this->args['url'] = !filter_var($url, FILTER_VALIDATE_URL)
99
+			? $this->postmeta->get($url)
100 100
 			: $url;
101 101
 	}
102 102
 
103
-	protected function normalize( $args )
103
+	protected function normalize($args)
104 104
 	{
105
-		if( is_string( $args )) {
105
+		if (is_string($args)) {
106 106
 			$args = ['url' => $args];
107 107
 		}
108 108
 
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 			'image'  => '', // string || int
111 111
 			'player' => '', // string || array
112 112
 			'url'    => '', // string
113
-		], $args );
113
+		], $args);
114 114
 
115
-		foreach( $this->args as $key => $value ) {
116
-			$method = $this->utility->buildMethodName( $key, 'set' );
117
-			if( !method_exists( $this, $method ))continue;
118
-			call_user_func([ $this, $method ], $value );
115
+		foreach ($this->args as $key => $value) {
116
+			$method = $this->utility->buildMethodName($key, 'set');
117
+			if (!method_exists($this, $method))continue;
118
+			call_user_func([$this, $method], $value);
119 119
 		}
120 120
 		return $this->args;
121 121
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,9 @@  discard block
 block discarded – undo
41 41
 
42 42
 	public function render()
43 43
 	{
44
-		if( !isset( $this->video->html ))return;
44
+		if( !isset( $this->video->html )) {
45
+			return;
46
+		}
45 47
 		return sprintf(
46 48
 			'<div class="video embed">%s%s</div>',
47 49
 			$this->renderScreenshot(),
@@ -114,7 +116,9 @@  discard block
 block discarded – undo
114 116
 
115 117
 		foreach( $this->args as $key => $value ) {
116 118
 			$method = $this->utility->buildMethodName( $key, 'set' );
117
-			if( !method_exists( $this, $method ))continue;
119
+			if( !method_exists( $this, $method )) {
120
+				continue;
121
+			}
118 122
 			call_user_func([ $this, $method ], $value );
119 123
 		}
120 124
 		return $this->args;
Please login to merge, or discard this patch.
src/Helpers/Template.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 {
9 9
 	public $util;
10 10
 
11
-	public function __construct( Utility $util )
11
+	public function __construct(Utility $util)
12 12
 	{
13 13
 		$this->util = $util;
14 14
 	}
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @return string
26 26
 	 */
27
-	public function get( $slug, $name = '' )
27
+	public function get($slug, $name = '')
28 28
 	{
29
-		$template  = $this->util->startWith( 'templates/', $slug );
29
+		$template  = $this->util->startWith('templates/', $slug);
30 30
 		$templates = ["{$template}.php"];
31 31
 
32
-		if( 'index' != basename( $this->template, '.php' )) {
33
-			$filepath = dirname( $template ) != '.'
34
-				? sprintf( '%s/', dirname( $template ))
32
+		if ('index' != basename($this->template, '.php')) {
33
+			$filepath = dirname($template) != '.'
34
+				? sprintf('%s/', dirname($template))
35 35
 				: '';
36 36
 			array_unshift(
37 37
 				$templates,
38
-				sprintf( '%s%s-%s.php', $filepath, $name, basename( $template ))
38
+				sprintf('%s%s-%s.php', $filepath, $name, basename($template))
39 39
 			);
40 40
 		}
41 41
 
42
-		$templates = apply_filters( "castor/templates/{$slug}", $templates, $name );
42
+		$templates = apply_filters("castor/templates/{$slug}", $templates, $name);
43 43
 
44
-		return locate_template( $templates );
44
+		return locate_template($templates);
45 45
 	}
46 46
 
47 47
 	/**
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @return void
52 52
 	 */
53
-	public function load( $slug, $name = '' )
53
+	public function load($slug, $name = '')
54 54
 	{
55
-		$template = $this->get( $slug, $name );
56
-		if( !empty( $template )) {
57
-			load_template( $template, false );
55
+		$template = $this->get($slug, $name);
56
+		if (!empty($template)) {
57
+			load_template($template, false);
58 58
 		}
59 59
 	}
60 60
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function main()
65 65
 	{
66
-		$this->load( $this->template );
66
+		$this->load($this->template);
67 67
 	}
68 68
 
69 69
 	/**
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @return string|void
73 73
 	 */
74
-	public function setLayout( $template )
74
+	public function setLayout($template)
75 75
 	{
76
-		$this->template = $this->util->trimRight( strstr( $template, 'templates/' ), '.php' );
77
-		return $this->get( apply_filters( 'castor/templates/layout', 'layouts/default' ));
76
+		$this->template = $this->util->trimRight(strstr($template, 'templates/'), '.php');
77
+		return $this->get(apply_filters('castor/templates/layout', 'layouts/default'));
78 78
 	}
79 79
 }
Please login to merge, or discard this patch.
src/Oembed.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -22,69 +22,69 @@
 block discarded – undo
22 22
 		'width',
23 23
 	];
24 24
 
25
-	public function __construct( Utility $utility )
25
+	public function __construct(Utility $utility)
26 26
 	{
27 27
 		$this->oembed  = _wp_oembed_get_object();
28 28
 		$this->utility = $utility;
29 29
 	}
30 30
 
31
-	public function request( $url, $args = '' )
31
+	public function request($url, $args = '')
32 32
 	{
33
-		$args = wp_parse_args( $args, [
33
+		$args = wp_parse_args($args, [
34 34
 			'embed_type' => '',
35 35
 		]);
36
-		$request = $this->oembed->fetch( $this->oembed->get_provider( $url ), $url, [
36
+		$request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [
37 37
 			'width'  => 1280,
38 38
 			'height' => 1280,
39 39
 		]);
40
-		if( $request === false )return;
41
-		if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type )return;
42
-		return $this->modifyRequest( $request, $args );
40
+		if ($request === false)return;
41
+		if (!empty($args['embed_type']) && $args['embed_type'] != $request->type)return;
42
+		return $this->modifyRequest($request, $args);
43 43
 	}
44 44
 
45
-	protected function domLoad( $html )
45
+	protected function domLoad($html)
46 46
 	{
47 47
 		$dom = new DomDocument;
48
-		$dom->loadHTML( $html );
48
+		$dom->loadHTML($html);
49 49
 		return $dom;
50 50
 	}
51 51
 
52
-	protected function modifyRequest( $request, $args )
52
+	protected function modifyRequest($request, $args)
53 53
 	{
54
-		$providerName = strtolower( $request->provider_name );
55
-		$provider = property_exists( $this, $providerName )
54
+		$providerName = strtolower($request->provider_name);
55
+		$provider = property_exists($this, $providerName)
56 56
 			? $this->$providerName
57 57
 			: [];
58 58
 
59
-		$method = $this->utility->buildMethodName( $providerName . '_request', 'modify' );
59
+		$method = $this->utility->buildMethodName($providerName . '_request', 'modify');
60 60
 
61
-		if( method_exists( $this, $method )) {
62
-			return call_user_func( [$this, $method], $request, array_intersect_key(
61
+		if (method_exists($this, $method)) {
62
+			return call_user_func([$this, $method], $request, array_intersect_key(
63 63
 				$args,
64
-				array_flip( $provider )
64
+				array_flip($provider)
65 65
 			));
66 66
 		}
67 67
 		return $request;
68 68
 	}
69 69
 
70
-	protected function modifyYoutubeRequest( $request, array $args )
70
+	protected function modifyYoutubeRequest($request, array $args)
71 71
 	{
72
-		$html = $this->domLoad( $request->html );
73
-		$node = $html->getElementsByTagName( 'iframe' )->item(0);
74
-		$url  = $node->getAttribute( 'src' );
72
+		$html = $this->domLoad($request->html);
73
+		$node = $html->getElementsByTagName('iframe')->item(0);
74
+		$url  = $node->getAttribute('src');
75 75
 
76
-		if( isset( $args['fs'] ) && $args['fs'] == 0 ) {
77
-			$node->removeAttribute( 'allowfullscreen' );
76
+		if (isset($args['fs']) && $args['fs'] == 0) {
77
+			$node->removeAttribute('allowfullscreen');
78 78
 		}
79 79
 
80
-		$args['origin'] = urlencode( get_bloginfo( 'url' ));
80
+		$args['origin'] = urlencode(get_bloginfo('url'));
81 81
 
82
-		$node->setAttribute( 'class', 'video-embed' );
83
-		$node->setAttribute( 'src',
84
-			add_query_arg( $args, remove_query_arg( 'feature', $url ))
82
+		$node->setAttribute('class', 'video-embed');
83
+		$node->setAttribute('src',
84
+			add_query_arg($args, remove_query_arg('feature', $url))
85 85
 		);
86 86
 
87
-		$request->html = $html->saveHTML( $node );
87
+		$request->html = $html->saveHTML($node);
88 88
 
89 89
 		return $request;
90 90
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,8 +37,12 @@
 block discarded – undo
37 37
 			'width'  => 1280,
38 38
 			'height' => 1280,
39 39
 		]);
40
-		if( $request === false )return;
41
-		if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type )return;
40
+		if( $request === false ) {
41
+			return;
42
+		}
43
+		if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type ) {
44
+			return;
45
+		}
42 46
 		return $this->modifyRequest( $request, $args );
43 47
 	}
44 48
 
Please login to merge, or discard this patch.
src/Email.php 2 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -62,7 +62,9 @@  discard block
 block discarded – undo
62 62
 		$this->to          = $email['to'];
63 63
 
64 64
 		add_action( 'phpmailer_init', function( PHPMailer $phpmailer ) {
65
-			if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return;
65
+			if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody )) {
66
+				return;
67
+			}
66 68
 			$phpmailer->AltBody = $this->buildPlainTextMessage( $phpmailer->Body );
67 69
 		});
68 70
 
@@ -86,7 +88,9 @@  discard block
 block discarded – undo
86 88
 	 */
87 89
 	public function send()
88 90
 	{
89
-		if( !$this->message || !$this->subject || !$this->to )return;
91
+		if( !$this->message || !$this->subject || !$this->to ) {
92
+			return;
93
+		}
90 94
 
91 95
 		$sent = wp_mail(
92 96
 			$this->to,
@@ -226,7 +230,9 @@  discard block
 block discarded – undo
226 230
 		if( !file_exists( $file )) {
227 231
 			$file = sprintf( '%s/templates/%s.php', dirname( __DIR__ ), $templatePath );
228 232
 		}
229
-		if( !file_exists( $file ))return;
233
+		if( !file_exists( $file )) {
234
+			return;
235
+		}
230 236
 
231 237
 		ob_start();
232 238
 		include $file;
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	protected $to;
44 44
 
45
-	public function __construct( Template $template, Utility $utility )
45
+	public function __construct(Template $template, Utility $utility)
46 46
 	{
47 47
 		$this->template = $template;
48 48
 		$this->utility  = $utility;
@@ -51,19 +51,19 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * @return Email
53 53
 	 */
54
-	public function compose( array $email )
54
+	public function compose(array $email)
55 55
 	{
56
-		$email = $this->normalize( $email );
56
+		$email = $this->normalize($email);
57 57
 
58 58
 		$this->attachments = $email['attachments'];
59
-		$this->headers     = $this->buildHeaders( $email );
60
-		$this->message     = $this->buildHtmlMessage( $email );
59
+		$this->headers     = $this->buildHeaders($email);
60
+		$this->message     = $this->buildHtmlMessage($email);
61 61
 		$this->subject     = $email['subject'];
62 62
 		$this->to          = $email['to'];
63 63
 
64
-		add_action( 'phpmailer_init', function( PHPMailer $phpmailer ) {
65
-			if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return;
66
-			$phpmailer->AltBody = $this->buildPlainTextMessage( $phpmailer->Body );
64
+		add_action('phpmailer_init', function(PHPMailer $phpmailer) {
65
+			if ($phpmailer->ContentType === 'text/plain' || !empty($phpmailer->AltBody))return;
66
+			$phpmailer->AltBody = $this->buildPlainTextMessage($phpmailer->Body);
67 67
 		});
68 68
 
69 69
 		return $this;
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return string|null
76 76
 	 */
77
-	public function read( $plaintext = false )
77
+	public function read($plaintext = false)
78 78
 	{
79 79
 		return $plaintext
80
-			? $this->buildPlainTextMessage( $this->message )
80
+			? $this->buildPlainTextMessage($this->message)
81 81
 			: $this->message;
82 82
 	}
83 83
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public function send()
88 88
 	{
89
-		if( !$this->message || !$this->subject || !$this->to )return;
89
+		if (!$this->message || !$this->subject || !$this->to)return;
90 90
 
91 91
 		$sent = wp_mail(
92 92
 			$this->to,
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	/**
105 105
 	 * @return array
106 106
 	 */
107
-	protected function buildHeaders( array $email )
107
+	protected function buildHeaders(array $email)
108 108
 	{
109 109
 		$allowed = [
110 110
 			'bcc',
@@ -113,34 +113,34 @@  discard block
 block discarded – undo
113 113
 			'reply-to',
114 114
 		];
115 115
 
116
-		$headers = array_intersect_key( $email, array_flip( $allowed ));
117
-		$headers = array_filter( $headers );
116
+		$headers = array_intersect_key($email, array_flip($allowed));
117
+		$headers = array_filter($headers);
118 118
 
119
-		foreach( $headers as $key => $value ) {
120
-			unset( $headers[ $key ] );
121
-			$headers[] = sprintf( '%s: %s', $key, $value );
119
+		foreach ($headers as $key => $value) {
120
+			unset($headers[$key]);
121
+			$headers[] = sprintf('%s: %s', $key, $value);
122 122
 		}
123 123
 
124 124
 		$headers[] = 'Content-Type: text/html';
125 125
 
126
-		return apply_filters( 'castor/email/headers', $headers, $this );
126
+		return apply_filters('castor/email/headers', $headers, $this);
127 127
 	}
128 128
 
129 129
 	/**
130 130
 	 * @return string
131 131
 	 */
132
-	protected function buildHtmlMessage( array $email )
132
+	protected function buildHtmlMessage(array $email)
133 133
 	{
134
-		$body = $this->renderTemplate( 'email' );
134
+		$body = $this->renderTemplate('email');
135 135
 
136
-		$message = !empty( $email['template'] )
137
-			? $this->renderTemplate( $email['template'], $email['template-tags'] )
136
+		$message = !empty($email['template'])
137
+			? $this->renderTemplate($email['template'], $email['template-tags'])
138 138
 			: $email['message'];
139 139
 
140
-		$message = $this->filterHtml( $email['before'] . $message . $email['after'] );
141
-		$message = str_replace( '{message}', $message, $body );
140
+		$message = $this->filterHtml($email['before'] . $message . $email['after']);
141
+		$message = str_replace('{message}', $message, $body);
142 142
 
143
-		return apply_filters( 'castor/email/message', $message, 'html', $this );
143
+		return apply_filters('castor/email/message', $message, 'html', $this);
144 144
 	}
145 145
 
146 146
 	/**
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @return string
150 150
 	 */
151
-	protected function buildPlainTextMessage( $message )
151
+	protected function buildPlainTextMessage($message)
152 152
 	{
153
-		return apply_filters( 'castor/email/message', $this->stripHtmlTags( $message ), 'text', $this );
153
+		return apply_filters('castor/email/message', $this->stripHtmlTags($message), 'text', $this);
154 154
 	}
155 155
 
156 156
 	/**
@@ -158,13 +158,13 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @return string
160 160
 	 */
161
-	protected function filterHtml( $message )
161
+	protected function filterHtml($message)
162 162
 	{
163
-		$message = strip_shortcodes( $message );
164
-		$message = wptexturize( $message );
165
-		$message = wpautop( $message );
166
-		$message = str_replace( ['&lt;&gt; ', ']]>'], ['', ']]&gt;'], $message );
167
-		$message = stripslashes( $message );
163
+		$message = strip_shortcodes($message);
164
+		$message = wptexturize($message);
165
+		$message = wpautop($message);
166
+		$message = str_replace(['&lt;&gt; ', ']]>'], ['', ']]&gt;'], $message);
167
+		$message = stripslashes($message);
168 168
 		return $message;
169 169
 	}
170 170
 
@@ -173,36 +173,36 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	protected function getDefaultFrom()
175 175
 	{
176
-		return sprintf( '%s <%s>',
177
-			wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
178
-			get_option( 'admin_email' )
176
+		return sprintf('%s <%s>',
177
+			wp_specialchars_decode(get_option('blogname'), ENT_QUOTES),
178
+			get_option('admin_email')
179 179
 		);
180 180
 	}
181 181
 
182 182
 	/**
183 183
 	 * @return array
184 184
 	 */
185
-	protected function normalize( $email )
185
+	protected function normalize($email)
186 186
 	{
187
-		$email = shortcode_atts( array_flip([
187
+		$email = shortcode_atts(array_flip([
188 188
 			'after', 'attachments', 'bcc', 'before', 'cc', 'from', 'message', 'reply-to', 'subject',
189 189
 			'template', 'template-tags', 'to',
190
-		]), $email );
190
+		]), $email);
191 191
 
192
-		foreach( ['attachments', 'template-tags'] as $key ) {
193
-			if( !is_array( $email[ $key ] )) {
194
-				$email[ $key ] = [];
192
+		foreach (['attachments', 'template-tags'] as $key) {
193
+			if (!is_array($email[$key])) {
194
+				$email[$key] = [];
195 195
 			}
196 196
 		}
197
-		if( empty( $email['from'] )) {
197
+		if (empty($email['from'])) {
198 198
 			$email['from'] = $this->getDefaultFrom();
199 199
 		}
200 200
 
201
-		if( empty( $email['reply-to'] )) {
201
+		if (empty($email['reply-to'])) {
202 202
 			$email['reply-to'] = $email['from'];
203 203
 		}
204 204
 
205
-		return apply_filters( 'castor/email/compose', $email, $this );
205
+		return apply_filters('castor/email/compose', $email, $this);
206 206
 	}
207 207
 
208 208
 	/**
@@ -222,20 +222,20 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @return void|string
224 224
 	 */
225
-	protected function renderTemplate( $templatePath, array $args = [] )
225
+	protected function renderTemplate($templatePath, array $args = [])
226 226
 	{
227
-		$file = $this->template->get( sprintf( 'castor/%s', $templatePath ));
227
+		$file = $this->template->get(sprintf('castor/%s', $templatePath));
228 228
 
229
-		if( !file_exists( $file )) {
230
-			$file = sprintf( '%s/templates/%s.php', dirname( __DIR__ ), $templatePath );
229
+		if (!file_exists($file)) {
230
+			$file = sprintf('%s/templates/%s.php', dirname(__DIR__), $templatePath);
231 231
 		}
232
-		if( !file_exists( $file ))return;
232
+		if (!file_exists($file))return;
233 233
 
234 234
 		ob_start();
235 235
 		include $file;
236 236
 		$template = ob_get_clean();
237 237
 
238
-		return $this->renderTemplateString( $template, $args );
238
+		return $this->renderTemplateString($template, $args);
239 239
 	}
240 240
 
241 241
 	/**
@@ -243,12 +243,12 @@  discard block
 block discarded – undo
243 243
 	 *
244 244
 	 * @return string
245 245
 	 */
246
-	protected function renderTemplateString( $template, array $args = [] )
246
+	protected function renderTemplateString($template, array $args = [])
247 247
 	{
248
-		foreach( $args as $key => $value ) {
249
-			$template = str_replace( sprintf( '{%s}', $key ), $value, $template );
248
+		foreach ($args as $key => $value) {
249
+			$template = str_replace(sprintf('{%s}', $key), $value, $template);
250 250
 		}
251
-		return trim( $template );
251
+		return trim($template);
252 252
 	}
253 253
 
254 254
 	/**
@@ -259,16 +259,16 @@  discard block
 block discarded – undo
259 259
 	 * - strip all remaining HTML tags
260 260
 	 * @return string
261 261
 	 */
262
-	protected function stripHtmlTags( $string )
262
+	protected function stripHtmlTags($string)
263 263
 	{
264
-		$string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string );
265
-		$string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string );
266
-		$string = preg_replace( '@</(td|th)@iu', " \$0", $string );
267
-		$string = preg_replace( '@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string );
268
-		$string = wp_strip_all_tags( $string );
269
-		$string = wp_specialchars_decode( $string, ENT_QUOTES );
270
-		$string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string );
271
-		$string = str_replace( '-o-^-o-', ' - ', $string );
272
-		return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
264
+		$string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string);
265
+		$string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string);
266
+		$string = preg_replace('@</(td|th)@iu', " \$0", $string);
267
+		$string = preg_replace('@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string);
268
+		$string = wp_strip_all_tags($string);
269
+		$string = wp_specialchars_decode($string, ENT_QUOTES);
270
+		$string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string);
271
+		$string = str_replace('-o-^-o-', ' - ', $string);
272
+		return html_entity_decode($string, ENT_QUOTES, 'UTF-8');
273 273
 	}
274 274
 }
Please login to merge, or discard this patch.
templates/email.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 <html>
3 3
 <head>
4 4
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
-    <title><?= wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); ?></title>
5
+    <title><?= wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); ?></title>
6 6
 </head>
7 7
 <body>
8 8
 
Please login to merge, or discard this patch.