@@ -12,7 +12,7 @@ discard block |
||
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 |
||
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 |
||
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 [ |
@@ -59,7 +59,9 @@ |
||
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 | } |
@@ -20,7 +20,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -41,7 +41,9 @@ discard block |
||
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 |
||
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; |
@@ -22,69 +22,69 @@ |
||
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 | } |
@@ -37,8 +37,12 @@ |
||
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 |
@@ -2,7 +2,7 @@ |
||
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 |
@@ -62,7 +62,9 @@ discard block |
||
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 |
||
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 |
||
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; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | protected $to; |
38 | 38 | |
39 | - public function __construct( Template $template ) |
|
39 | + public function __construct(Template $template) |
|
40 | 40 | { |
41 | 41 | $this->template = $template; |
42 | 42 | } |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | /** |
45 | 45 | * @return Email |
46 | 46 | */ |
47 | - public function compose( array $email ) |
|
47 | + public function compose(array $email) |
|
48 | 48 | { |
49 | - $email = $this->normalize( $email ); |
|
49 | + $email = $this->normalize($email); |
|
50 | 50 | |
51 | 51 | $this->attachments = $email['attachments']; |
52 | - $this->headers = $this->buildHeaders( $email ); |
|
53 | - $this->message = $this->buildHtmlMessage( $email ); |
|
52 | + $this->headers = $this->buildHeaders($email); |
|
53 | + $this->message = $this->buildHtmlMessage($email); |
|
54 | 54 | $this->subject = $email['subject']; |
55 | 55 | $this->to = $email['to']; |
56 | 56 | |
57 | - add_action( 'phpmailer_init', function( PHPMailer $phpmailer ) { |
|
58 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return; |
|
59 | - $phpmailer->AltBody = $this->buildPlainTextMessage( $phpmailer->Body ); |
|
57 | + add_action('phpmailer_init', function(PHPMailer $phpmailer) { |
|
58 | + if ($phpmailer->ContentType === 'text/plain' || !empty($phpmailer->AltBody))return; |
|
59 | + $phpmailer->AltBody = $this->buildPlainTextMessage($phpmailer->Body); |
|
60 | 60 | }); |
61 | 61 | |
62 | 62 | return $this; |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return string|null |
69 | 69 | */ |
70 | - public function read( $plaintext = false ) |
|
70 | + public function read($plaintext = false) |
|
71 | 71 | { |
72 | 72 | return $plaintext |
73 | - ? $this->buildPlainTextMessage( $this->message ) |
|
73 | + ? $this->buildPlainTextMessage($this->message) |
|
74 | 74 | : $this->message; |
75 | 75 | } |
76 | 76 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function send() |
81 | 81 | { |
82 | - if( !$this->message || !$this->subject || !$this->to )return; |
|
82 | + if (!$this->message || !$this->subject || !$this->to)return; |
|
83 | 83 | |
84 | 84 | $sent = wp_mail( |
85 | 85 | $this->to, |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | /** |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - protected function buildHeaders( array $email ) |
|
100 | + protected function buildHeaders(array $email) |
|
101 | 101 | { |
102 | 102 | $allowed = [ |
103 | 103 | 'bcc', |
@@ -106,34 +106,34 @@ discard block |
||
106 | 106 | 'reply-to', |
107 | 107 | ]; |
108 | 108 | |
109 | - $headers = array_intersect_key( $email, array_flip( $allowed )); |
|
110 | - $headers = array_filter( $headers ); |
|
109 | + $headers = array_intersect_key($email, array_flip($allowed)); |
|
110 | + $headers = array_filter($headers); |
|
111 | 111 | |
112 | - foreach( $headers as $key => $value ) { |
|
113 | - unset( $headers[ $key ] ); |
|
114 | - $headers[] = sprintf( '%s: %s', $key, $value ); |
|
112 | + foreach ($headers as $key => $value) { |
|
113 | + unset($headers[$key]); |
|
114 | + $headers[] = sprintf('%s: %s', $key, $value); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $headers[] = 'Content-Type: text/html'; |
118 | 118 | |
119 | - return apply_filters( 'castor/email/headers', $headers, $this ); |
|
119 | + return apply_filters('castor/email/headers', $headers, $this); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @return string |
124 | 124 | */ |
125 | - protected function buildHtmlMessage( array $email ) |
|
125 | + protected function buildHtmlMessage(array $email) |
|
126 | 126 | { |
127 | - $body = $this->renderTemplate( 'email' ); |
|
127 | + $body = $this->renderTemplate('email'); |
|
128 | 128 | |
129 | - $message = !empty( $email['template'] ) |
|
130 | - ? $this->renderTemplate( $email['template'], $email['template-tags'] ) |
|
129 | + $message = !empty($email['template']) |
|
130 | + ? $this->renderTemplate($email['template'], $email['template-tags']) |
|
131 | 131 | : $email['message']; |
132 | 132 | |
133 | - $message = $this->filterHtml( $email['before'] . $message . $email['after'] ); |
|
134 | - $message = str_replace( '{message}', $message, $body ); |
|
133 | + $message = $this->filterHtml($email['before'] . $message . $email['after']); |
|
134 | + $message = str_replace('{message}', $message, $body); |
|
135 | 135 | |
136 | - return apply_filters( 'castor/email/message', $message, 'html', $this ); |
|
136 | + return apply_filters('castor/email/message', $message, 'html', $this); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return string |
143 | 143 | */ |
144 | - protected function buildPlainTextMessage( $message ) |
|
144 | + protected function buildPlainTextMessage($message) |
|
145 | 145 | { |
146 | - return apply_filters( 'castor/email/message', $this->stripHtmlTags( $message ), 'text', $this ); |
|
146 | + return apply_filters('castor/email/message', $this->stripHtmlTags($message), 'text', $this); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @return string |
153 | 153 | */ |
154 | - protected function filterHtml( $message ) |
|
154 | + protected function filterHtml($message) |
|
155 | 155 | { |
156 | - $message = strip_shortcodes( $message ); |
|
157 | - $message = wptexturize( $message ); |
|
158 | - $message = wpautop( $message ); |
|
159 | - $message = str_replace( ['<> ', ']]>'], ['', ']]>'], $message ); |
|
160 | - $message = stripslashes( $message ); |
|
156 | + $message = strip_shortcodes($message); |
|
157 | + $message = wptexturize($message); |
|
158 | + $message = wpautop($message); |
|
159 | + $message = str_replace(['<> ', ']]>'], ['', ']]>'], $message); |
|
160 | + $message = stripslashes($message); |
|
161 | 161 | return $message; |
162 | 162 | } |
163 | 163 | |
@@ -166,33 +166,33 @@ discard block |
||
166 | 166 | */ |
167 | 167 | protected function getDefaultFrom() |
168 | 168 | { |
169 | - return sprintf( '%s <%s>', |
|
170 | - wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
|
171 | - get_option( 'admin_email' ) |
|
169 | + return sprintf('%s <%s>', |
|
170 | + wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), |
|
171 | + get_option('admin_email') |
|
172 | 172 | ); |
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - protected function normalize( $email ) |
|
178 | + protected function normalize($email) |
|
179 | 179 | { |
180 | 180 | $defaults = array_fill_keys([ |
181 | 181 | 'after', 'attachments', 'bcc', 'before', 'cc', 'from', 'message', 'reply-to', 'subject', |
182 | 182 | 'template', 'template-tags', 'to', |
183 | - ], '' ); |
|
183 | + ], ''); |
|
184 | 184 | $defaults['from'] = $this->getDefaultFrom(); |
185 | 185 | |
186 | - $email = shortcode_atts( $defaults, $email ); |
|
186 | + $email = shortcode_atts($defaults, $email); |
|
187 | 187 | |
188 | - foreach( ['attachments', 'template-tags'] as $key ) { |
|
189 | - $email[$key] = array_filter( (array) $email[$key] ); |
|
188 | + foreach (['attachments', 'template-tags'] as $key) { |
|
189 | + $email[$key] = array_filter((array) $email[$key]); |
|
190 | 190 | } |
191 | - if( empty( $email['reply-to'] )) { |
|
191 | + if (empty($email['reply-to'])) { |
|
192 | 192 | $email['reply-to'] = $email['from']; |
193 | 193 | } |
194 | 194 | |
195 | - return apply_filters( 'castor/email/compose', $email, $this ); |
|
195 | + return apply_filters('castor/email/compose', $email, $this); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -202,20 +202,20 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return void|string |
204 | 204 | */ |
205 | - protected function renderTemplate( $templatePath, array $args = [] ) |
|
205 | + protected function renderTemplate($templatePath, array $args = []) |
|
206 | 206 | { |
207 | - $file = $this->template->get( sprintf( 'castor/%s', $templatePath )); |
|
207 | + $file = $this->template->get(sprintf('castor/%s', $templatePath)); |
|
208 | 208 | |
209 | - if( !file_exists( $file )) { |
|
210 | - $file = sprintf( '%s/templates/%s.php', dirname( __DIR__ ), $templatePath ); |
|
209 | + if (!file_exists($file)) { |
|
210 | + $file = sprintf('%s/templates/%s.php', dirname(__DIR__), $templatePath); |
|
211 | 211 | } |
212 | - if( !file_exists( $file ))return; |
|
212 | + if (!file_exists($file))return; |
|
213 | 213 | |
214 | 214 | ob_start(); |
215 | 215 | include $file; |
216 | 216 | $template = ob_get_clean(); |
217 | 217 | |
218 | - return $this->renderTemplateString( $template, $args ); |
|
218 | + return $this->renderTemplateString($template, $args); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - protected function renderTemplateString( $template, array $args = [] ) |
|
226 | + protected function renderTemplateString($template, array $args = []) |
|
227 | 227 | { |
228 | - foreach( $args as $key => $value ) { |
|
229 | - $template = str_replace( sprintf( '{%s}', $key ), $value, $template ); |
|
228 | + foreach ($args as $key => $value) { |
|
229 | + $template = str_replace(sprintf('{%s}', $key), $value, $template); |
|
230 | 230 | } |
231 | - return trim( $template ); |
|
231 | + return trim($template); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -251,16 +251,16 @@ discard block |
||
251 | 251 | * - strip all remaining HTML tags |
252 | 252 | * @return string |
253 | 253 | */ |
254 | - protected function stripHtmlTags( $string ) |
|
254 | + protected function stripHtmlTags($string) |
|
255 | 255 | { |
256 | - $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string ); |
|
257 | - $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string ); |
|
258 | - $string = preg_replace( '@</(td|th)@iu', " \$0", $string ); |
|
259 | - $string = preg_replace( '@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string ); |
|
260 | - $string = wp_strip_all_tags( $string ); |
|
261 | - $string = wp_specialchars_decode( $string, ENT_QUOTES ); |
|
262 | - $string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string ); |
|
263 | - $string = str_replace( '-o-^-o-', ' - ', $string ); |
|
264 | - return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' ); |
|
256 | + $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
257 | + $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
258 | + $string = preg_replace('@</(td|th)@iu', " \$0", $string); |
|
259 | + $string = preg_replace('@<(li)[^>]*?>@siu', "\$0-o-^-o-", $string); |
|
260 | + $string = wp_strip_all_tags($string); |
|
261 | + $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
262 | + $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
263 | + $string = str_replace('-o-^-o-', ' - ', $string); |
|
264 | + return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
265 | 265 | } |
266 | 266 | } |
@@ -148,7 +148,9 @@ discard block |
||
148 | 148 | |
149 | 149 | // normalize truthy boolean attributes |
150 | 150 | foreach( $filtered as $key => $value ) { |
151 | - if( !in_array( $key, self::BOOLEAN_ATTRIBUTES ))continue; |
|
151 | + if( !in_array( $key, self::BOOLEAN_ATTRIBUTES )) { |
|
152 | + continue; |
|
153 | + } |
|
152 | 154 | |
153 | 155 | if( $value !== false ) { |
154 | 156 | $filtered[ $key ] = ''; |
@@ -187,11 +189,15 @@ discard block |
||
187 | 189 | |
188 | 190 | if( $result ) { |
189 | 191 | // only allow data attributes to have an empty value |
190 | - if( $wildcard != 'data-' && empty( $value ))continue; |
|
192 | + if( $wildcard != 'data-' && empty( $value )) { |
|
193 | + continue; |
|
194 | + } |
|
191 | 195 | |
192 | 196 | if( is_array( $value )) { |
193 | 197 | |
194 | - if( $wildcard != 'data-' )continue; |
|
198 | + if( $wildcard != 'data-' ) { |
|
199 | + continue; |
|
200 | + } |
|
195 | 201 | |
196 | 202 | $value = json_encode( $value ); |
197 | 203 | } |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return array|string |
66 | 66 | */ |
67 | - public function form( array $args = [], $implode = false ) |
|
67 | + public function form(array $args = [], $implode = false) |
|
68 | 68 | { |
69 | - $attributes = $this->parseAttributes( self::FORM_ATTRIBUTES, $args ); |
|
69 | + $attributes = $this->parseAttributes(self::FORM_ATTRIBUTES, $args); |
|
70 | 70 | |
71 | - return $this->maybeImplode( $attributes, $implode ); |
|
71 | + return $this->maybeImplode($attributes, $implode); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return array|string |
78 | 78 | */ |
79 | - public function input( array $args = [], $implode = false ) |
|
79 | + public function input(array $args = [], $implode = false) |
|
80 | 80 | { |
81 | 81 | $this->filterInputType(); |
82 | 82 | |
83 | - $attributes = $this->parseAttributes( self::INPUT_ATTRIBUTES, $args ); |
|
83 | + $attributes = $this->parseAttributes(self::INPUT_ATTRIBUTES, $args); |
|
84 | 84 | |
85 | - return $this->maybeImplode( $attributes, $implode ); |
|
85 | + return $this->maybeImplode($attributes, $implode); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return array|string |
94 | 94 | */ |
95 | - public function maybeImplode( array $attributes, $implode = true ) |
|
95 | + public function maybeImplode(array $attributes, $implode = true) |
|
96 | 96 | { |
97 | - if( !$implode || $implode !== 'implode' ) { |
|
97 | + if (!$implode || $implode !== 'implode') { |
|
98 | 98 | return $attributes; |
99 | 99 | } |
100 | 100 | $results = []; |
101 | - foreach( $attributes as $key => $value ) { |
|
101 | + foreach ($attributes as $key => $value) { |
|
102 | 102 | // if data attributes, use single quotes in case of json encoded values |
103 | - $quotes = false !== stripos( $key, 'data-' ) ? "'" : '"'; |
|
104 | - if( is_array( $value )) { |
|
105 | - $value = json_encode( $value ); |
|
103 | + $quotes = false !== stripos($key, 'data-') ? "'" : '"'; |
|
104 | + if (is_array($value)) { |
|
105 | + $value = json_encode($value); |
|
106 | 106 | $quotes = "'"; |
107 | 107 | } |
108 | - $results[] = is_string( $key ) |
|
109 | - ? sprintf( '%1$s=%3$s%2$s%3$s', $key, $value, $quotes ) |
|
108 | + $results[] = is_string($key) |
|
109 | + ? sprintf('%1$s=%3$s%2$s%3$s', $key, $value, $quotes) |
|
110 | 110 | : $value; |
111 | 111 | } |
112 | - return implode( ' ', $results ); |
|
112 | + return implode(' ', $results); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return array|string |
119 | 119 | */ |
120 | - public function select( array $args = [], $implode = false ) |
|
120 | + public function select(array $args = [], $implode = false) |
|
121 | 121 | { |
122 | - $attributes = $this->parseAttributes( self::SELECT_ATTRIBUTES, $args ); |
|
122 | + $attributes = $this->parseAttributes(self::SELECT_ATTRIBUTES, $args); |
|
123 | 123 | |
124 | - return $this->maybeImplode( $attributes, $implode ); |
|
124 | + return $this->maybeImplode($attributes, $implode); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return array|string |
131 | 131 | */ |
132 | - public function textarea( array $args = [], $implode = false ) |
|
132 | + public function textarea(array $args = [], $implode = false) |
|
133 | 133 | { |
134 | - $attributes = $this->parseAttributes( self::TEXTAREA_ATTRIBUTES, $args ); |
|
134 | + $attributes = $this->parseAttributes(self::TEXTAREA_ATTRIBUTES, $args); |
|
135 | 135 | |
136 | - return $this->maybeImplode( $attributes, $implode ); |
|
136 | + return $this->maybeImplode($attributes, $implode); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -142,31 +142,31 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @return array |
144 | 144 | */ |
145 | - protected function filterAttributes( array $attributeKeys ) |
|
145 | + protected function filterAttributes(array $attributeKeys) |
|
146 | 146 | { |
147 | - $filtered = array_intersect_key( $this->args, array_flip( $attributeKeys )); |
|
147 | + $filtered = array_intersect_key($this->args, array_flip($attributeKeys)); |
|
148 | 148 | |
149 | 149 | // normalize truthy boolean attributes |
150 | - foreach( $filtered as $key => $value ) { |
|
151 | - if( !in_array( $key, self::BOOLEAN_ATTRIBUTES ))continue; |
|
150 | + foreach ($filtered as $key => $value) { |
|
151 | + if (!in_array($key, self::BOOLEAN_ATTRIBUTES))continue; |
|
152 | 152 | |
153 | - if( $value !== false ) { |
|
154 | - $filtered[ $key ] = ''; |
|
153 | + if ($value !== false) { |
|
154 | + $filtered[$key] = ''; |
|
155 | 155 | continue; |
156 | 156 | } |
157 | 157 | |
158 | - unset( $filtered[ $key ] ); |
|
158 | + unset($filtered[$key]); |
|
159 | 159 | } |
160 | 160 | |
161 | - $filteredKeys = array_filter( array_keys( $filtered ), function( $key ) use ( $filtered ) { |
|
161 | + $filteredKeys = array_filter(array_keys($filtered), function($key) use ($filtered) { |
|
162 | 162 | return !( |
163 | - empty( $filtered[ $key ] ) |
|
164 | - && !is_numeric( $filtered[ $key ] ) |
|
165 | - && !in_array( $key, self::BOOLEAN_ATTRIBUTES ) |
|
163 | + empty($filtered[$key]) |
|
164 | + && !is_numeric($filtered[$key]) |
|
165 | + && !in_array($key, self::BOOLEAN_ATTRIBUTES) |
|
166 | 166 | ); |
167 | 167 | }); |
168 | 168 | |
169 | - return array_intersect_key( $filtered, array_flip( $filteredKeys )); |
|
169 | + return array_intersect_key($filtered, array_flip($filteredKeys)); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -174,34 +174,34 @@ discard block |
||
174 | 174 | */ |
175 | 175 | protected function filterGlobalAttributes() |
176 | 176 | { |
177 | - $global = $this->filterAttributes( self::GLOBAL_ATTRIBUTES ); |
|
177 | + $global = $this->filterAttributes(self::GLOBAL_ATTRIBUTES); |
|
178 | 178 | |
179 | 179 | $wildcards = []; |
180 | 180 | |
181 | - foreach( self::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) { |
|
181 | + foreach (self::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
182 | 182 | |
183 | - foreach( $this->args as $key => $value ) { |
|
183 | + foreach ($this->args as $key => $value) { |
|
184 | 184 | |
185 | - $length = strlen( $wildcard ); |
|
186 | - $result = substr( $key, 0, $length) === $wildcard; |
|
185 | + $length = strlen($wildcard); |
|
186 | + $result = substr($key, 0, $length) === $wildcard; |
|
187 | 187 | |
188 | - if( $result ) { |
|
188 | + if ($result) { |
|
189 | 189 | // only allow data attributes to have an empty value |
190 | - if( $wildcard != 'data-' && empty( $value ))continue; |
|
190 | + if ($wildcard != 'data-' && empty($value))continue; |
|
191 | 191 | |
192 | - if( is_array( $value )) { |
|
192 | + if (is_array($value)) { |
|
193 | 193 | |
194 | - if( $wildcard != 'data-' )continue; |
|
194 | + if ($wildcard != 'data-')continue; |
|
195 | 195 | |
196 | - $value = json_encode( $value ); |
|
196 | + $value = json_encode($value); |
|
197 | 197 | } |
198 | 198 | |
199 | - $wildcards[ $key ] = $value; |
|
199 | + $wildcards[$key] = $value; |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - return array_merge( $global, $wildcards ); |
|
204 | + return array_merge($global, $wildcards); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | protected function filterInputType() |
211 | 211 | { |
212 | - if( !isset( $this->args['type'] ) || !in_array( $this->args['type'], self::INPUT_TYPES )) { |
|
212 | + if (!isset($this->args['type']) || !in_array($this->args['type'], self::INPUT_TYPES)) { |
|
213 | 213 | $this->args['type'] = 'text'; |
214 | 214 | } |
215 | 215 | } |
@@ -217,15 +217,15 @@ discard block |
||
217 | 217 | /** |
218 | 218 | * @return array |
219 | 219 | */ |
220 | - protected function parseAttributes( array $attributes, array $args = [] ) |
|
220 | + protected function parseAttributes(array $attributes, array $args = []) |
|
221 | 221 | { |
222 | - if( !empty( $args )) { |
|
223 | - $this->args = array_change_key_case( $args ); |
|
222 | + if (!empty($args)) { |
|
223 | + $this->args = array_change_key_case($args); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | $global = $this->filterGlobalAttributes(); |
227 | - $local = $this->filterAttributes( $attributes ); |
|
227 | + $local = $this->filterAttributes($attributes); |
|
228 | 228 | |
229 | - return array_merge( $global, $local ); |
|
229 | + return array_merge($global, $local); |
|
230 | 230 | } |
231 | 231 | } |
@@ -78,7 +78,9 @@ discard block |
||
78 | 78 | foreach( $rules as $rule ) { |
79 | 79 | $this->validateAttribute( $rule, $attribute ); |
80 | 80 | |
81 | - if( $this->shouldStopValidating( $attribute ))break; |
|
81 | + if( $this->shouldStopValidating( $attribute )) { |
|
82 | + break; |
|
83 | + } |
|
82 | 84 | } |
83 | 85 | } |
84 | 86 | |
@@ -161,7 +163,9 @@ discard block |
||
161 | 163 | */ |
162 | 164 | protected function getRule( $attribute, $rules ) |
163 | 165 | { |
164 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
166 | + if( !array_key_exists( $attribute, $this->rules )) { |
|
167 | + return; |
|
168 | + } |
|
165 | 169 | |
166 | 170 | $rules = (array) $rules; |
167 | 171 | |
@@ -188,8 +192,7 @@ discard block |
||
188 | 192 | |
189 | 193 | if( is_numeric( $value ) && $hasNumeric ) { |
190 | 194 | return $value; |
191 | - } |
|
192 | - elseif( is_array( $value )) { |
|
195 | + } elseif( is_array( $value )) { |
|
193 | 196 | return count( $value ); |
194 | 197 | } |
195 | 198 | |
@@ -253,8 +256,7 @@ discard block |
||
253 | 256 | // If an object was provided, get its public properties |
254 | 257 | if( is_object( $data )) { |
255 | 258 | $this->data = get_object_vars( $data ); |
256 | - } |
|
257 | - else { |
|
259 | + } else { |
|
258 | 260 | $this->data = $data; |
259 | 261 | } |
260 | 262 | |
@@ -420,7 +422,9 @@ discard block |
||
420 | 422 | ? $strings[ $key ] |
421 | 423 | : false; |
422 | 424 | |
423 | - if( !$message )return; |
|
425 | + if( !$message ) { |
|
426 | + return; |
|
427 | + } |
|
424 | 428 | |
425 | 429 | $message = str_replace( ':attribute', $attribute, $message ); |
426 | 430 | |
@@ -464,7 +468,9 @@ discard block |
||
464 | 468 | { |
465 | 469 | list( $rule, $parameters ) = $this->parseRule( $rule ); |
466 | 470 | |
467 | - if( $rule == '' )return; |
|
471 | + if( $rule == '' ) { |
|
472 | + return; |
|
473 | + } |
|
468 | 474 | |
469 | 475 | $method = "validate{$rule}"; |
470 | 476 |
@@ -69,16 +69,16 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return array |
71 | 71 | */ |
72 | - public function validate( $data, array $rules = [] ) |
|
72 | + public function validate($data, array $rules = []) |
|
73 | 73 | { |
74 | - $this->normalizeData( $data ); |
|
75 | - $this->setRules( $rules ); |
|
74 | + $this->normalizeData($data); |
|
75 | + $this->setRules($rules); |
|
76 | 76 | |
77 | - foreach( $this->rules as $attribute => $rules ) { |
|
78 | - foreach( $rules as $rule ) { |
|
79 | - $this->validateAttribute( $rule, $attribute ); |
|
77 | + foreach ($this->rules as $attribute => $rules) { |
|
78 | + foreach ($rules as $rule) { |
|
79 | + $this->validateAttribute($rule, $attribute); |
|
80 | 80 | |
81 | - if( $this->shouldStopValidating( $attribute ))break; |
|
81 | + if ($this->shouldStopValidating($attribute))break; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return void |
95 | 95 | */ |
96 | - protected function addError( $attribute, $rule, array $parameters ) |
|
96 | + protected function addError($attribute, $rule, array $parameters) |
|
97 | 97 | { |
98 | - $message = $this->getMessage( $attribute, $rule, $parameters ); |
|
98 | + $message = $this->getMessage($attribute, $rule, $parameters); |
|
99 | 99 | |
100 | - $this->errors[ $attribute ]['errors'][] = $message; |
|
100 | + $this->errors[$attribute]['errors'][] = $message; |
|
101 | 101 | |
102 | - if( !isset( $this->errors[ $attribute ]['value'] )) { |
|
103 | - $this->errors[ $attribute ]['value'] = $this->getValue( $attribute ); |
|
102 | + if (!isset($this->errors[$attribute]['value'])) { |
|
103 | + $this->errors[$attribute]['value'] = $this->getValue($attribute); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - protected function addFailure( $attribute, $rule, array $parameters ) |
|
115 | + protected function addFailure($attribute, $rule, array $parameters) |
|
116 | 116 | { |
117 | - $this->addError( $attribute, $rule, $parameters ); |
|
117 | + $this->addError($attribute, $rule, $parameters); |
|
118 | 118 | |
119 | - $this->failedRules[ $attribute ][ $rule ] = $parameters; |
|
119 | + $this->failedRules[$attribute][$rule] = $parameters; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param string $attribute |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - protected function getAttributeType( $attribute ) |
|
128 | + protected function getAttributeType($attribute) |
|
129 | 129 | { |
130 | - return $this->hasRule( $attribute, $this->numericRules ) |
|
130 | + return $this->hasRule($attribute, $this->numericRules) |
|
131 | 131 | ? 'numeric' |
132 | 132 | : 'string'; |
133 | 133 | } |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return string|null |
142 | 142 | */ |
143 | - protected function getMessage( $attribute, $rule, array $parameters ) |
|
143 | + protected function getMessage($attribute, $rule, array $parameters) |
|
144 | 144 | { |
145 | - if( in_array( $rule, $this->sizeRules )) { |
|
146 | - return $this->getSizeMessage( $attribute, $rule, $parameters ); |
|
145 | + if (in_array($rule, $this->sizeRules)) { |
|
146 | + return $this->getSizeMessage($attribute, $rule, $parameters); |
|
147 | 147 | } |
148 | 148 | |
149 | - $lowerRule = $this->snakeCase( $rule ); |
|
149 | + $lowerRule = $this->snakeCase($rule); |
|
150 | 150 | |
151 | - return $this->translator( $lowerRule, $rule, $attribute, $parameters ); |
|
151 | + return $this->translator($lowerRule, $rule, $attribute, $parameters); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return array|null |
161 | 161 | */ |
162 | - protected function getRule( $attribute, $rules ) |
|
162 | + protected function getRule($attribute, $rules) |
|
163 | 163 | { |
164 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
164 | + if (!array_key_exists($attribute, $this->rules))return; |
|
165 | 165 | |
166 | 166 | $rules = (array) $rules; |
167 | 167 | |
168 | - foreach( $this->rules[ $attribute ] as $rule ) { |
|
169 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
168 | + foreach ($this->rules[$attribute] as $rule) { |
|
169 | + list($rule, $parameters) = $this->parseRule($rule); |
|
170 | 170 | |
171 | - if( in_array( $rule, $rules )) { |
|
172 | - return [ $rule, $parameters ]; |
|
171 | + if (in_array($rule, $rules)) { |
|
172 | + return [$rule, $parameters]; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return mixed |
184 | 184 | */ |
185 | - protected function getSize( $attribute, $value ) |
|
185 | + protected function getSize($attribute, $value) |
|
186 | 186 | { |
187 | - $hasNumeric = $this->hasRule( $attribute, $this->numericRules ); |
|
187 | + $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
|
188 | 188 | |
189 | - if( is_numeric( $value ) && $hasNumeric ) { |
|
189 | + if (is_numeric($value) && $hasNumeric) { |
|
190 | 190 | return $value; |
191 | 191 | } |
192 | - elseif( is_array( $value )) { |
|
193 | - return count( $value ); |
|
192 | + elseif (is_array($value)) { |
|
193 | + return count($value); |
|
194 | 194 | } |
195 | 195 | |
196 | - return mb_strlen( $value ); |
|
196 | + return mb_strlen($value); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -204,14 +204,14 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @return string|null |
206 | 206 | */ |
207 | - protected function getSizeMessage( $attribute, $rule, array $parameters ) |
|
207 | + protected function getSizeMessage($attribute, $rule, array $parameters) |
|
208 | 208 | { |
209 | - $lowerRule = $this->snakeCase( $rule ); |
|
210 | - $type = $this->getAttributeType( $attribute ); |
|
209 | + $lowerRule = $this->snakeCase($rule); |
|
210 | + $type = $this->getAttributeType($attribute); |
|
211 | 211 | |
212 | 212 | $lowerRule .= ".{$type}"; |
213 | 213 | |
214 | - return $this->translator( $lowerRule, $rule, $attribute, $parameters ); |
|
214 | + return $this->translator($lowerRule, $rule, $attribute, $parameters); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return mixed |
223 | 223 | */ |
224 | - protected function getValue( $attribute ) |
|
224 | + protected function getValue($attribute) |
|
225 | 225 | { |
226 | - if( isset( $this->data[ $attribute ] )) { |
|
227 | - return $this->data[ $attribute ]; |
|
226 | + if (isset($this->data[$attribute])) { |
|
227 | + return $this->data[$attribute]; |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return bool |
238 | 238 | */ |
239 | - protected function hasRule( $attribute, $rules ) |
|
239 | + protected function hasRule($attribute, $rules) |
|
240 | 240 | { |
241 | - return !is_null( $this->getRule( $attribute, $rules )); |
|
241 | + return !is_null($this->getRule($attribute, $rules)); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @return $this |
250 | 250 | */ |
251 | - protected function normalizeData( $data ) |
|
251 | + protected function normalizeData($data) |
|
252 | 252 | { |
253 | 253 | // If an object was provided, get its public properties |
254 | - if( is_object( $data )) { |
|
255 | - $this->data = get_object_vars( $data ); |
|
254 | + if (is_object($data)) { |
|
255 | + $this->data = get_object_vars($data); |
|
256 | 256 | } |
257 | 257 | else { |
258 | 258 | $this->data = $data; |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return array |
271 | 271 | */ |
272 | - protected function parseParameters( $rule, $parameter ) |
|
272 | + protected function parseParameters($rule, $parameter) |
|
273 | 273 | { |
274 | - if( strtolower( $rule ) == 'regex' ) { |
|
275 | - return [ $parameter ]; |
|
274 | + if (strtolower($rule) == 'regex') { |
|
275 | + return [$parameter]; |
|
276 | 276 | } |
277 | 277 | |
278 | - return str_getcsv( $parameter ); |
|
278 | + return str_getcsv($parameter); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -285,22 +285,22 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array |
287 | 287 | */ |
288 | - protected function parseRule( $rule ) |
|
288 | + protected function parseRule($rule) |
|
289 | 289 | { |
290 | 290 | $parameters = []; |
291 | 291 | |
292 | 292 | // example: {rule}:{parameters} |
293 | - if( strpos( $rule, ':' ) !== false ) { |
|
294 | - list( $rule, $parameter ) = explode( ':', $rule, 2 ); |
|
293 | + if (strpos($rule, ':') !== false) { |
|
294 | + list($rule, $parameter) = explode(':', $rule, 2); |
|
295 | 295 | |
296 | 296 | // example: {parameter1,parameter2,...} |
297 | - $parameters = $this->parseParameters( $rule, $parameter ); |
|
297 | + $parameters = $this->parseParameters($rule, $parameter); |
|
298 | 298 | } |
299 | 299 | |
300 | - $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ))); |
|
301 | - $rule = str_replace( ' ', '', $rule ); |
|
300 | + $rule = ucwords(str_replace(['-', '_'], ' ', trim($rule))); |
|
301 | + $rule = str_replace(' ', '', $rule); |
|
302 | 302 | |
303 | - return [ $rule, $parameters ]; |
|
303 | + return [$rule, $parameters]; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -310,9 +310,9 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - protected function replaceBetween( $message, array $parameters ) |
|
313 | + protected function replaceBetween($message, array $parameters) |
|
314 | 314 | { |
315 | - return str_replace([':min', ':max'], $parameters, $message ); |
|
315 | + return str_replace([':min', ':max'], $parameters, $message); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @return string |
324 | 324 | */ |
325 | - protected function replaceMax( $message, array $parameters ) |
|
325 | + protected function replaceMax($message, array $parameters) |
|
326 | 326 | { |
327 | - return str_replace( ':max', $parameters[0], $message ); |
|
327 | + return str_replace(':max', $parameters[0], $message); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @return string |
336 | 336 | */ |
337 | - protected function replaceMin( $message, array $parameters ) |
|
337 | + protected function replaceMin($message, array $parameters) |
|
338 | 338 | { |
339 | - return str_replace( ':min', $parameters[0], $message ); |
|
339 | + return str_replace(':min', $parameters[0], $message); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -348,10 +348,10 @@ discard block |
||
348 | 348 | * @return void |
349 | 349 | * @throws InvalidArgumentException |
350 | 350 | */ |
351 | - protected function requireParameterCount( $count, array $parameters, $rule ) |
|
351 | + protected function requireParameterCount($count, array $parameters, $rule) |
|
352 | 352 | { |
353 | - if( count( $parameters ) < $count ) { |
|
354 | - throw new InvalidArgumentException( "Validation rule $rule requires at least $count parameters." ); |
|
353 | + if (count($parameters) < $count) { |
|
354 | + throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @return $this |
362 | 362 | */ |
363 | - protected function setRules( array $rules ) |
|
363 | + protected function setRules(array $rules) |
|
364 | 364 | { |
365 | - foreach( $rules as $key => $rule ) { |
|
366 | - $rules[ $key ] = is_string( $rule ) ? explode( '|', $rule ) : $rule; |
|
365 | + foreach ($rules as $key => $rule) { |
|
366 | + $rules[$key] = is_string($rule) ? explode('|', $rule) : $rule; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $this->rules = $rules; |
@@ -378,11 +378,11 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - protected function shouldStopValidating( $attribute ) |
|
381 | + protected function shouldStopValidating($attribute) |
|
382 | 382 | { |
383 | - return $this->hasRule( $attribute, $this->implicitRules ) |
|
384 | - && isset( $this->failedRules[ $attribute ] ) |
|
385 | - && array_intersect( array_keys( $this->failedRules[ $attribute ] ), $this->implicitRules ); |
|
383 | + return $this->hasRule($attribute, $this->implicitRules) |
|
384 | + && isset($this->failedRules[$attribute]) |
|
385 | + && array_intersect(array_keys($this->failedRules[$attribute]), $this->implicitRules); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -392,12 +392,12 @@ discard block |
||
392 | 392 | * |
393 | 393 | * @return string |
394 | 394 | */ |
395 | - protected function snakeCase( $string ) |
|
395 | + protected function snakeCase($string) |
|
396 | 396 | { |
397 | - if( !ctype_lower( $string )) { |
|
398 | - $string = preg_replace( '/\s+/u', '', $string ); |
|
399 | - $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
400 | - $string = mb_strtolower( $string, 'UTF-8' ); |
|
397 | + if (!ctype_lower($string)) { |
|
398 | + $string = preg_replace('/\s+/u', '', $string); |
|
399 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
400 | + $string = mb_strtolower($string, 'UTF-8'); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | return $string; |
@@ -412,20 +412,20 @@ discard block |
||
412 | 412 | * |
413 | 413 | * @return string|null |
414 | 414 | */ |
415 | - protected function translator( $key, $rule, $attribute, array $parameters ) |
|
415 | + protected function translator($key, $rule, $attribute, array $parameters) |
|
416 | 416 | { |
417 | - $strings = glsr_resolve( 'Strings' )->validation(); |
|
417 | + $strings = glsr_resolve('Strings')->validation(); |
|
418 | 418 | |
419 | - $message = isset( $strings[ $key ] ) |
|
420 | - ? $strings[ $key ] |
|
419 | + $message = isset($strings[$key]) |
|
420 | + ? $strings[$key] |
|
421 | 421 | : false; |
422 | 422 | |
423 | - if( !$message )return; |
|
423 | + if (!$message)return; |
|
424 | 424 | |
425 | - $message = str_replace( ':attribute', $attribute, $message ); |
|
425 | + $message = str_replace(':attribute', $attribute, $message); |
|
426 | 426 | |
427 | - if( method_exists( $this, $replacer = "replace{$rule}" )) { |
|
428 | - $message = $this->$replacer( $message, $parameters ); |
|
427 | + if (method_exists($this, $replacer = "replace{$rule}")) { |
|
428 | + $message = $this->$replacer($message, $parameters); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | return $message; |
@@ -443,11 +443,11 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @return bool |
445 | 445 | */ |
446 | - protected function validateAccepted( $value ) |
|
446 | + protected function validateAccepted($value) |
|
447 | 447 | { |
448 | 448 | $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
449 | 449 | |
450 | - return $this->validateRequired( $value ) && in_array( $value, $acceptable, true ); |
|
450 | + return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -459,20 +459,20 @@ discard block |
||
459 | 459 | * @return void |
460 | 460 | * @throws BadMethodCallException |
461 | 461 | */ |
462 | - protected function validateAttribute( $rule, $attribute ) |
|
462 | + protected function validateAttribute($rule, $attribute) |
|
463 | 463 | { |
464 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
464 | + list($rule, $parameters) = $this->parseRule($rule); |
|
465 | 465 | |
466 | - if( $rule == '' )return; |
|
466 | + if ($rule == '')return; |
|
467 | 467 | |
468 | 468 | $method = "validate{$rule}"; |
469 | 469 | |
470 | - if( !method_exists( $this, $method )) { |
|
471 | - throw new BadMethodCallException( "Method [$method] does not exist." ); |
|
470 | + if (!method_exists($this, $method)) { |
|
471 | + throw new BadMethodCallException("Method [$method] does not exist."); |
|
472 | 472 | } |
473 | 473 | |
474 | - if( !$this->$method( $this->getValue( $attribute ), $attribute, $parameters )) { |
|
475 | - $this->addFailure( $attribute, $rule, $parameters ); |
|
474 | + if (!$this->$method($this->getValue($attribute), $attribute, $parameters)) { |
|
475 | + $this->addFailure($attribute, $rule, $parameters); |
|
476 | 476 | } |
477 | 477 | } |
478 | 478 | |
@@ -484,11 +484,11 @@ discard block |
||
484 | 484 | * |
485 | 485 | * @return bool |
486 | 486 | */ |
487 | - protected function validateBetween( $value, $attribute, array $parameters ) |
|
487 | + protected function validateBetween($value, $attribute, array $parameters) |
|
488 | 488 | { |
489 | - $this->requireParameterCount( 2, $parameters, 'between' ); |
|
489 | + $this->requireParameterCount(2, $parameters, 'between'); |
|
490 | 490 | |
491 | - $size = $this->getSize( $attribute, $value ); |
|
491 | + $size = $this->getSize($attribute, $value); |
|
492 | 492 | |
493 | 493 | return $size >= $parameters[0] && $size <= $parameters[1]; |
494 | 494 | } |
@@ -500,9 +500,9 @@ discard block |
||
500 | 500 | * |
501 | 501 | * @return bool |
502 | 502 | */ |
503 | - protected function validateEmail( $value ) |
|
503 | + protected function validateEmail($value) |
|
504 | 504 | { |
505 | - return filter_var( $value, FILTER_VALIDATE_EMAIL ) !== false; |
|
505 | + return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @return bool |
515 | 515 | */ |
516 | - protected function validateMax( $value, $attribute, array $parameters ) |
|
516 | + protected function validateMax($value, $attribute, array $parameters) |
|
517 | 517 | { |
518 | - $this->requireParameterCount( 1, $parameters, 'max' ); |
|
518 | + $this->requireParameterCount(1, $parameters, 'max'); |
|
519 | 519 | |
520 | - return $this->getSize( $attribute, $value ) <= $parameters[0]; |
|
520 | + return $this->getSize($attribute, $value) <= $parameters[0]; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -528,11 +528,11 @@ discard block |
||
528 | 528 | * |
529 | 529 | * @return bool |
530 | 530 | */ |
531 | - protected function validateMin( $value, $attribute, array $parameters ) |
|
531 | + protected function validateMin($value, $attribute, array $parameters) |
|
532 | 532 | { |
533 | - $this->requireParameterCount( 1, $parameters, 'min' ); |
|
533 | + $this->requireParameterCount(1, $parameters, 'min'); |
|
534 | 534 | |
535 | - return $this->getSize( $attribute, $value ) >= $parameters[0]; |
|
535 | + return $this->getSize($attribute, $value) >= $parameters[0]; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -542,9 +542,9 @@ discard block |
||
542 | 542 | * |
543 | 543 | * @return bool |
544 | 544 | */ |
545 | - protected function validateNumeric( $value ) |
|
545 | + protected function validateNumeric($value) |
|
546 | 546 | { |
547 | - return is_numeric( $value ); |
|
547 | + return is_numeric($value); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
@@ -554,12 +554,12 @@ discard block |
||
554 | 554 | * |
555 | 555 | * @return bool |
556 | 556 | */ |
557 | - protected function validateRequired( $value ) |
|
557 | + protected function validateRequired($value) |
|
558 | 558 | { |
559 | - if( is_string( $value )) { |
|
560 | - $value = trim( $value ); |
|
559 | + if (is_string($value)) { |
|
560 | + $value = trim($value); |
|
561 | 561 | } |
562 | - return is_null( $value ) || empty( $value ) |
|
562 | + return is_null($value) || empty($value) |
|
563 | 563 | ? false |
564 | 564 | : true; |
565 | 565 | } |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | { |
9 | 9 | protected $element = 'input'; |
10 | 10 | |
11 | - public function __construct( array $args = [] ) |
|
11 | + public function __construct(array $args = []) |
|
12 | 12 | { |
13 | - parent::__construct( $args ); |
|
13 | + parent::__construct($args); |
|
14 | 14 | |
15 | - if( count( $args['options'] ) > 1 ) { |
|
15 | + if (count($args['options']) > 1) { |
|
16 | 16 | $this->multi = true; |
17 | 17 | } |
18 | 18 | } |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | { |
25 | 25 | $inline = $this->args['inline'] ? ' class="inline"' : ''; |
26 | 26 | |
27 | - if( $this->multi ) { |
|
28 | - return sprintf( '<ul%s>%s</ul>%s', |
|
27 | + if ($this->multi) { |
|
28 | + return sprintf('<ul%s>%s</ul>%s', |
|
29 | 29 | $inline, |
30 | - $this->implodeOptions( 'multi_input_checkbox' ), |
|
30 | + $this->implodeOptions('multi_input_checkbox'), |
|
31 | 31 | $this->generateDescription() |
32 | 32 | ); |
33 | 33 | } |
34 | 34 | |
35 | - return sprintf( '%s%s', |
|
36 | - $this->implodeOptions( 'single_input' ), |
|
35 | + return sprintf('%s%s', |
|
36 | + $this->implodeOptions('single_input'), |
|
37 | 37 | $this->generateDescription() |
38 | 38 | ); |
39 | 39 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( $default = null ) |
|
14 | + public function render($default = null) |
|
15 | 15 | { |
16 | 16 | $inline = $this->args['inline'] ? ' class="inline"' : ''; |
17 | 17 | |
18 | - return sprintf( '<ul%s>%s</ul>%s', |
|
18 | + return sprintf('<ul%s>%s</ul>%s', |
|
19 | 19 | $inline, |
20 | - $this->implodeOptions( 'multi_input', $default ), |
|
20 | + $this->implodeOptions('multi_input', $default), |
|
21 | 21 | $this->generateDescription() |
22 | 22 | ); |
23 | 23 | } |