@@ -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((string) get_option('blogname'), ENT_QUOTES); ?></title> |
|
5 | + <title><?= wp_specialchars_decode( (string) get_option( 'blogname' ), ENT_QUOTES ); ?></title> |
|
6 | 6 | </head> |
7 | 7 | <body> |
8 | 8 |
@@ -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' != $attachment->post_type) { |
|
62 | + if( is_null( $attachment ) || 'attachment' != $attachment->post_type ) { |
|
63 | 63 | return; |
64 | 64 | } |
65 | 65 | |
@@ -71,16 +71,16 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return array |
73 | 73 | */ |
74 | - protected function normalizeSrc(array $image, $fallback = false) |
|
74 | + protected function normalizeSrc( array $image, $fallback = false ) |
|
75 | 75 | { |
76 | - if (is_array($fallback) && count(array_diff($image, $fallback)) < 2) { |
|
76 | + if( is_array( $fallback ) && count( array_diff( $image, $fallback ) ) < 2 ) { |
|
77 | 77 | $image = $fallback; |
78 | 78 | } |
79 | - $image = array_pad($image, 3, ''); |
|
79 | + $image = array_pad( $image, 3, '' ); |
|
80 | 80 | return [ |
81 | - 'url' => array_shift($image), |
|
82 | - 'width' => array_shift($image), |
|
83 | - 'height' => array_shift($image), |
|
81 | + 'url' => array_shift( $image ), |
|
82 | + 'width' => array_shift( $image ), |
|
83 | + 'height' => array_shift( $image ), |
|
84 | 84 | ]; |
85 | 85 | } |
86 | 86 | } |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | * @return mixed |
30 | 30 | * @throws \RuntimeException |
31 | 31 | */ |
32 | - public static function __callStatic($method, $args) |
|
32 | + public static function __callStatic( $method, $args ) |
|
33 | 33 | { |
34 | 34 | $instance = static::getFacadeRoot(); |
35 | 35 | |
36 | - if (!$instance) { |
|
37 | - throw new RuntimeException('A facade root has not been set.'); |
|
36 | + if( !$instance ) { |
|
37 | + throw new RuntimeException( 'A facade root has not been set.' ); |
|
38 | 38 | } |
39 | 39 | |
40 | - return $instance->$method(...$args); |
|
40 | + return $instance->$method( ...$args ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public static function getFacadeRoot() |
69 | 69 | { |
70 | - return static::resolveFacadeInstance(static::getFacadeAccessor()); |
|
70 | + return static::resolveFacadeInstance( static::getFacadeAccessor() ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return void |
77 | 77 | */ |
78 | - public static function setFacadeApplication(Application $app) |
|
78 | + public static function setFacadeApplication( Application $app ) |
|
79 | 79 | { |
80 | 80 | static::$app = $app; |
81 | 81 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | protected static function getFacadeAccessor() |
91 | 91 | { |
92 | - throw new RuntimeException('Facade does not implement getFacadeAccessor method.'); |
|
92 | + throw new RuntimeException( 'Facade does not implement getFacadeAccessor method.' ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,16 +99,16 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return mixed |
101 | 101 | */ |
102 | - protected static function resolveFacadeInstance($name) |
|
102 | + protected static function resolveFacadeInstance( $name ) |
|
103 | 103 | { |
104 | - if (is_object($name)) { |
|
104 | + if( is_object( $name ) ) { |
|
105 | 105 | return $name; |
106 | 106 | } |
107 | 107 | |
108 | - if (isset(static::$resolvedInstance[$name])) { |
|
108 | + if( isset( static::$resolvedInstance[$name] ) ) { |
|
109 | 109 | return static::$resolvedInstance[$name]; |
110 | 110 | } |
111 | 111 | |
112 | - return static::$resolvedInstance[$name] = static::$app->make($name); |
|
112 | + return static::$resolvedInstance[$name] = static::$app->make( $name ); |
|
113 | 113 | } |
114 | 114 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | protected $theme; |
19 | 19 | protected $utility; |
20 | 20 | |
21 | - public function __construct(Image $image, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
21 | + public function __construct( Image $image, PostMeta $postmeta, Theme $theme, Utility $utility ) |
|
22 | 22 | { |
23 | 23 | $this->image = $image; |
24 | 24 | $this->postmeta = $postmeta; |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @return static |
31 | 31 | */ |
32 | - public function get(array $args = []) |
|
32 | + public function get( array $args = [] ) |
|
33 | 33 | { |
34 | - $this->normalizeArgs($args); |
|
34 | + $this->normalizeArgs( $args ); |
|
35 | 35 | |
36 | - $this->gallery = new WP_Query([ |
|
36 | + $this->gallery = new WP_Query( [ |
|
37 | 37 | 'orderby' => 'post__in', |
38 | 38 | 'paged' => $this->getPaged(), |
39 | 39 | 'post__in' => $this->args['media'], |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | 'post_type' => 'attachment', |
42 | 42 | 'post_status' => 'inherit', |
43 | 43 | 'posts_per_page' => $this->args['images_per_page'], |
44 | - ]); |
|
44 | + ] ); |
|
45 | 45 | return $this; |
46 | 46 | } |
47 | 47 | |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function render() |
52 | 52 | { |
53 | - if (empty($this->args['media'])) { |
|
53 | + if( empty( $this->args['media'] ) ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | - $images = array_reduce($this->gallery->posts, function ($images, $attachment) { |
|
57 | - return $images.$this->renderImage($attachment); |
|
56 | + $images = array_reduce( $this->gallery->posts, function( $images, $attachment ) { |
|
57 | + return $images.$this->renderImage( $attachment ); |
|
58 | 58 | }); |
59 | - return sprintf('<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>%s', |
|
59 | + return sprintf( '<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>%s', |
|
60 | 60 | $images, |
61 | 61 | $this->renderPagination() |
62 | 62 | ); |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * @return string|null |
67 | 67 | */ |
68 | - public function renderImage(WP_Post $attachment) |
|
68 | + public function renderImage( WP_Post $attachment ) |
|
69 | 69 | { |
70 | - $image = $this->image->get($attachment->ID)->image; |
|
70 | + $image = $this->image->get( $attachment->ID )->image; |
|
71 | 71 | |
72 | - if (!$image) { |
|
72 | + if( !$image ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | return sprintf( |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | '</figure>', |
79 | 79 | $image->thumbnail['width'], |
80 | 80 | $image->thumbnail['height'], |
81 | - $this->getPhotoswipeData($image), |
|
82 | - $this->renderImageTag($image), |
|
83 | - $this->renderImageCaption($image) |
|
81 | + $this->getPhotoswipeData( $image ), |
|
82 | + $this->renderImageTag( $image ), |
|
83 | + $this->renderImageCaption( $image ) |
|
84 | 84 | ); |
85 | 85 | } |
86 | 86 | |
@@ -89,17 +89,17 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function renderPagination() |
91 | 91 | { |
92 | - if (!$this->args['pagination']) { |
|
92 | + if( !$this->args['pagination'] ) { |
|
93 | 93 | return; |
94 | 94 | } |
95 | - return paginate_links([ |
|
96 | - 'before_page_number' => '<span class="screen-reader-text">'.__('Page', 'castor').' </span>', |
|
95 | + return paginate_links( [ |
|
96 | + 'before_page_number' => '<span class="screen-reader-text">'.__( 'Page', 'castor' ).' </span>', |
|
97 | 97 | 'current' => $this->gallery->query['paged'], |
98 | 98 | 'mid_size' => 1, |
99 | - 'next_text' => __('Next', 'castor'), |
|
100 | - 'prev_text' => __('Previous', 'castor'), |
|
99 | + 'next_text' => __( 'Next', 'castor' ), |
|
100 | + 'prev_text' => __( 'Previous', 'castor' ), |
|
101 | 101 | 'total' => $this->gallery->max_num_pages, |
102 | - ]); |
|
102 | + ] ); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return bool |
110 | 110 | */ |
111 | - protected function getBoolValue($key, $value = null) |
|
111 | + protected function getBoolValue( $key, $value = null ) |
|
112 | 112 | { |
113 | - $bool = $this->getValue($key, $value); |
|
113 | + $bool = $this->getValue( $key, $value ); |
|
114 | 114 | |
115 | - if (is_null(filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))) { |
|
116 | - $bool = $this->postmeta->get($bool); |
|
115 | + if( is_null( filter_var( $bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) ) ) { |
|
116 | + $bool = $this->postmeta->get( $bool ); |
|
117 | 117 | } |
118 | - return wp_validate_boolean($bool); |
|
118 | + return wp_validate_boolean( $bool ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return int |
125 | 125 | */ |
126 | - protected function getGalleryArg($value = null) |
|
126 | + protected function getGalleryArg( $value = null ) |
|
127 | 127 | { |
128 | - $gallery = $this->getValue('gallery', $value); |
|
128 | + $gallery = $this->getValue( 'gallery', $value ); |
|
129 | 129 | |
130 | - if (!is_numeric($gallery) && is_string($gallery)) { |
|
131 | - $gallery = intval($this->postmeta->get($gallery)); |
|
130 | + if( !is_numeric( $gallery ) && is_string( $gallery ) ) { |
|
131 | + $gallery = intval( $this->postmeta->get( $gallery ) ); |
|
132 | 132 | } |
133 | - return !is_null(get_post($gallery)) |
|
134 | - ? intval($gallery) |
|
133 | + return !is_null( get_post( $gallery ) ) |
|
134 | + ? intval( $gallery ) |
|
135 | 135 | : 0; |
136 | 136 | } |
137 | 137 | |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return int |
142 | 142 | */ |
143 | - protected function getImagesPerPageArg($value = null) |
|
143 | + protected function getImagesPerPageArg( $value = null ) |
|
144 | 144 | { |
145 | - $perPage = $this->getValue('images_per_page', $value); |
|
145 | + $perPage = $this->getValue( 'images_per_page', $value ); |
|
146 | 146 | |
147 | - if (!is_numeric($perPage) && is_string($perPage)) { |
|
148 | - $perPage = $this->postmeta->get($perPage); |
|
147 | + if( !is_numeric( $perPage ) && is_string( $perPage ) ) { |
|
148 | + $perPage = $this->postmeta->get( $perPage ); |
|
149 | 149 | } |
150 | - return (bool) intval($perPage) |
|
150 | + return (bool) intval( $perPage ) |
|
151 | 151 | ? $perPage |
152 | 152 | : -1; |
153 | 153 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return bool |
159 | 159 | */ |
160 | - protected function getLazyloadArg($value = null) |
|
160 | + protected function getLazyloadArg( $value = null ) |
|
161 | 161 | { |
162 | - return $this->getBoolValue('lazyload', $value); |
|
162 | + return $this->getBoolValue( 'lazyload', $value ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -167,18 +167,18 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - protected function getMediaArg($value = null) |
|
170 | + protected function getMediaArg( $value = null ) |
|
171 | 171 | { |
172 | - $media = $this->getValue('media', $value); |
|
172 | + $media = $this->getValue( 'media', $value ); |
|
173 | 173 | |
174 | - if (is_string($media)) { |
|
175 | - $media = $this->postmeta->get($media, [ |
|
174 | + if( is_string( $media ) ) { |
|
175 | + $media = $this->postmeta->get( $media, [ |
|
176 | 176 | 'ID' => $this->getGalleryArg(), |
177 | 177 | 'single' => false, |
178 | - ]); |
|
178 | + ] ); |
|
179 | 179 | } |
180 | - return is_array($media) |
|
181 | - ? wp_parse_id_list($media) |
|
180 | + return is_array( $media ) |
|
181 | + ? wp_parse_id_list( $media ) |
|
182 | 182 | : []; |
183 | 183 | } |
184 | 184 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | protected function getPaged() |
189 | 189 | { |
190 | - return intval(get_query_var((is_front_page() ? 'page' : 'paged'))) ?: 1; |
|
190 | + return intval( get_query_var( ( is_front_page() ? 'page' : 'paged' ) ) ) ?: 1; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @return bool |
197 | 197 | */ |
198 | - protected function getPaginationArg($value = null) |
|
198 | + protected function getPaginationArg( $value = null ) |
|
199 | 199 | { |
200 | - return $this->getBoolValue('pagination', $value); |
|
200 | + return $this->getBoolValue( 'pagination', $value ); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -205,17 +205,17 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return bool |
207 | 207 | */ |
208 | - protected function getPermalinksArg($value = null) |
|
208 | + protected function getPermalinksArg( $value = null ) |
|
209 | 209 | { |
210 | - return $this->getBoolValue('permalinks', $value); |
|
210 | + return $this->getBoolValue( 'permalinks', $value ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | 214 | * @return string |
215 | 215 | */ |
216 | - protected function getPhotoswipeData($image) |
|
216 | + protected function getPhotoswipeData( $image ) |
|
217 | 217 | { |
218 | - return sprintf('{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
218 | + return sprintf( '{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
219 | 219 | $image->large['url'], |
220 | 220 | $image->large['width'], |
221 | 221 | $image->large['height'], |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return mixed |
233 | 233 | */ |
234 | - protected function getValue($key, $value = null) |
|
234 | + protected function getValue( $key, $value = null ) |
|
235 | 235 | { |
236 | - if (is_null($value) && isset($this->args[$key])) { |
|
236 | + if( is_null( $value ) && isset( $this->args[$key] ) ) { |
|
237 | 237 | $value = $this->args[$key]; |
238 | 238 | } |
239 | 239 | return $value; |
@@ -242,23 +242,23 @@ discard block |
||
242 | 242 | /** |
243 | 243 | * @return array |
244 | 244 | */ |
245 | - protected function normalizeArgs(array $args = []) |
|
245 | + protected function normalizeArgs( array $args = [] ) |
|
246 | 246 | { |
247 | 247 | $defaults = [ |
248 | - 'gallery', // (string) meta_key | (int) post_id |
|
249 | - 'lazyload', // (string) meta_key | (bool) |
|
250 | - 'media', // (string) meta_key | (array) post_ids |
|
251 | - 'pagination', // (string) meta_key | (bool) |
|
248 | + 'gallery', // (string) meta_key | (int) post_id |
|
249 | + 'lazyload', // (string) meta_key | (bool) |
|
250 | + 'media', // (string) meta_key | (array) post_ids |
|
251 | + 'pagination', // (string) meta_key | (bool) |
|
252 | 252 | 'images_per_page', // (string) meta_key | (int) number |
253 | - 'permalinks', // (string) meta_key | (bool) |
|
253 | + 'permalinks', // (string) meta_key | (bool) |
|
254 | 254 | ]; |
255 | 255 | |
256 | - $this->args = shortcode_atts(array_combine($defaults, $defaults), $args); |
|
256 | + $this->args = shortcode_atts( array_combine( $defaults, $defaults ), $args ); |
|
257 | 257 | |
258 | - array_walk($this->args, function (&$value, $key) { |
|
259 | - $method = $this->utility->buildMethodName($key.'_arg'); |
|
260 | - if (method_exists($this, $method)) { |
|
261 | - $value = call_user_func([$this, $method], $value); |
|
258 | + array_walk( $this->args, function( &$value, $key ) { |
|
259 | + $method = $this->utility->buildMethodName( $key.'_arg' ); |
|
260 | + if( method_exists( $this, $method ) ) { |
|
261 | + $value = call_user_func( [$this, $method], $value ); |
|
262 | 262 | } |
263 | 263 | }); |
264 | 264 | |
@@ -269,35 +269,35 @@ discard block |
||
269 | 269 | * @param object $image |
270 | 270 | * @return string|null |
271 | 271 | */ |
272 | - protected function renderImageCaption($image) |
|
272 | + protected function renderImageCaption( $image ) |
|
273 | 273 | { |
274 | - if (!empty($image->copyright)) { |
|
275 | - $image->caption .= sprintf(' <span itemprop="copyrightHolder">%s</span>', $image->copyright); |
|
274 | + if( !empty( $image->copyright ) ) { |
|
275 | + $image->caption .= sprintf( ' <span itemprop="copyrightHolder">%s</span>', $image->copyright ); |
|
276 | 276 | } |
277 | - if (empty($image->caption)) { |
|
277 | + if( empty( $image->caption ) ) { |
|
278 | 278 | return; |
279 | 279 | } |
280 | - return sprintf('<figcaption itemprop="caption description">%s</figcaption>', $image->caption); |
|
280 | + return sprintf( '<figcaption itemprop="caption description">%s</figcaption>', $image->caption ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
284 | 284 | * @param object $image |
285 | 285 | * @return string|null |
286 | 286 | */ |
287 | - protected function renderImageTag($image) |
|
287 | + protected function renderImageTag( $image ) |
|
288 | 288 | { |
289 | 289 | $imgSrc = $this->getLazyloadArg() |
290 | - ? $this->theme->imageUri('blank.gif') |
|
290 | + ? $this->theme->imageUri( 'blank.gif' ) |
|
291 | 291 | : $image->thumbnail['url']; |
292 | 292 | |
293 | - $imgTag = sprintf('<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
293 | + $imgTag = sprintf( '<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
294 | 294 | $imgSrc, |
295 | 295 | $image->thumbnail['url'], |
296 | 296 | $image->alt |
297 | 297 | ); |
298 | 298 | |
299 | 299 | return $this->getPermalinksArg() |
300 | - ? sprintf('<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag) |
|
300 | + ? sprintf( '<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag ) |
|
301 | 301 | : $imgTag; |
302 | 302 | } |
303 | 303 | } |
@@ -22,73 +22,73 @@ |
||
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 | - ]); |
|
36 | - $request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [ |
|
35 | + ] ); |
|
36 | + $request = $this->oembed->fetch( $this->oembed->get_provider( $url ), $url, [ |
|
37 | 37 | 'width' => 1280, |
38 | 38 | 'height' => 1280, |
39 | - ]); |
|
40 | - if (false === $request) { |
|
39 | + ] ); |
|
40 | + if( false === $request ) { |
|
41 | 41 | return; |
42 | 42 | } |
43 | - if (!empty($args['embed_type']) && $args['embed_type'] != $request->type) { |
|
43 | + if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type ) { |
|
44 | 44 | return; |
45 | 45 | } |
46 | - return $this->modifyRequest($request, $args); |
|
46 | + return $this->modifyRequest( $request, $args ); |
|
47 | 47 | } |
48 | 48 | |
49 | - protected function domLoad($html) |
|
49 | + protected function domLoad( $html ) |
|
50 | 50 | { |
51 | 51 | $dom = new DomDocument(); |
52 | - $dom->loadHTML($html); |
|
52 | + $dom->loadHTML( $html ); |
|
53 | 53 | return $dom; |
54 | 54 | } |
55 | 55 | |
56 | - protected function modifyRequest($request, $args) |
|
56 | + protected function modifyRequest( $request, $args ) |
|
57 | 57 | { |
58 | - $providerName = strtolower($request->provider_name); |
|
59 | - $provider = property_exists($this, $providerName) |
|
58 | + $providerName = strtolower( $request->provider_name ); |
|
59 | + $provider = property_exists( $this, $providerName ) |
|
60 | 60 | ? $this->$providerName |
61 | 61 | : []; |
62 | 62 | |
63 | - $method = $this->utility->buildMethodName($providerName.'_request', 'modify'); |
|
63 | + $method = $this->utility->buildMethodName( $providerName.'_request', 'modify' ); |
|
64 | 64 | |
65 | - if (method_exists($this, $method)) { |
|
66 | - return call_user_func([$this, $method], $request, array_intersect_key( |
|
65 | + if( method_exists( $this, $method ) ) { |
|
66 | + return call_user_func( [$this, $method], $request, array_intersect_key( |
|
67 | 67 | $args, |
68 | - array_flip($provider) |
|
69 | - )); |
|
68 | + array_flip( $provider ) |
|
69 | + ) ); |
|
70 | 70 | } |
71 | 71 | return $request; |
72 | 72 | } |
73 | 73 | |
74 | - protected function modifyYoutubeRequest($request, array $args) |
|
74 | + protected function modifyYoutubeRequest( $request, array $args ) |
|
75 | 75 | { |
76 | - $html = $this->domLoad($request->html); |
|
77 | - $node = $html->getElementsByTagName('iframe')->item(0); |
|
78 | - $url = $node->getAttribute('src'); |
|
76 | + $html = $this->domLoad( $request->html ); |
|
77 | + $node = $html->getElementsByTagName( 'iframe' )->item( 0 ); |
|
78 | + $url = $node->getAttribute( 'src' ); |
|
79 | 79 | |
80 | - if (isset($args['fs']) && 0 == $args['fs']) { |
|
81 | - $node->removeAttribute('allowfullscreen'); |
|
80 | + if( isset( $args['fs'] ) && 0 == $args['fs'] ) { |
|
81 | + $node->removeAttribute( 'allowfullscreen' ); |
|
82 | 82 | } |
83 | 83 | |
84 | - $args['origin'] = urlencode(get_bloginfo('url')); |
|
84 | + $args['origin'] = urlencode( get_bloginfo( 'url' ) ); |
|
85 | 85 | |
86 | - $node->setAttribute('class', 'video-embed'); |
|
87 | - $node->setAttribute('src', |
|
88 | - add_query_arg($args, remove_query_arg('feature', $url)) |
|
86 | + $node->setAttribute( 'class', 'video-embed' ); |
|
87 | + $node->setAttribute( 'src', |
|
88 | + add_query_arg( $args, remove_query_arg( 'feature', $url ) ) |
|
89 | 89 | ); |
90 | 90 | |
91 | - $request->html = $html->saveHTML($node); |
|
91 | + $request->html = $html->saveHTML( $node ); |
|
92 | 92 | |
93 | 93 | return $request; |
94 | 94 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | protected $theme; |
19 | 19 | protected $utility; |
20 | 20 | |
21 | - public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
21 | + public function __construct( Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility ) |
|
22 | 22 | { |
23 | 23 | $this->image = $image; |
24 | 24 | $this->oembed = $oembed; |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | $this->utility = $utility; |
28 | 28 | } |
29 | 29 | |
30 | - public function get($args = []) |
|
30 | + public function get( $args = [] ) |
|
31 | 31 | { |
32 | - $args = $this->normalize($args); |
|
33 | - $embed = $this->oembed->request($args['url'], $args['player']); |
|
34 | - if (isset($embed->type) && 'video' == $embed->type) { |
|
32 | + $args = $this->normalize( $args ); |
|
33 | + $embed = $this->oembed->request( $args['url'], $args['player'] ); |
|
34 | + if( isset( $embed->type ) && 'video' == $embed->type ) { |
|
35 | 35 | $this->video = $embed; |
36 | 36 | } |
37 | 37 | return $this; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | public function render() |
41 | 41 | { |
42 | - if (!isset($this->video->html)) { |
|
42 | + if( !isset( $this->video->html ) ) { |
|
43 | 43 | return; |
44 | 44 | } |
45 | 45 | return sprintf( |
@@ -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,43 +81,43 @@ 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 | |
109 | - $this->args = shortcode_atts([ |
|
109 | + $this->args = shortcode_atts( [ |
|
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)) { |
|
115 | + foreach( $this->args as $key => $value ) { |
|
116 | + $method = $this->utility->buildMethodName( $key, 'set' ); |
|
117 | + if( !method_exists( $this, $method ) ) { |
|
118 | 118 | continue; |
119 | 119 | } |
120 | - call_user_func([$this, $method], $value); |
|
120 | + call_user_func( [$this, $method], $value ); |
|
121 | 121 | } |
122 | 122 | return $this->args; |
123 | 123 | } |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - $option = apply_filters('pollux/archives/id', 'pollux_archives'); |
|
21 | - $this->options = (array) get_option($option, []); |
|
20 | + $option = apply_filters( 'pollux/archives/id', 'pollux_archives' ); |
|
21 | + $this->options = (array) get_option( $option, [] ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | * @param string $group |
28 | 28 | * @return mixed |
29 | 29 | */ |
30 | - public function get($key = '', $fallback = null, $group = '') |
|
30 | + public function get( $key = '', $fallback = null, $group = '' ) |
|
31 | 31 | { |
32 | - return parent::get($group, $key, $fallback); |
|
32 | + return parent::get( $group, $key, $fallback ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -19,22 +19,22 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public function get($slug, $name = '') |
|
22 | + public function get( $slug, $name = '' ) |
|
23 | 23 | { |
24 | - $template = UtilityFacade::startWith('templates/', $slug); |
|
24 | + $template = UtilityFacade::startWith( 'templates/', $slug ); |
|
25 | 25 | $templates = ["$template.php"]; |
26 | - if (!empty($name)) { |
|
27 | - $fileName = basename($template); |
|
28 | - $filePath = UtilityFacade::trimRight($template, $fileName); |
|
29 | - array_unshift($templates, sprintf('%s/%s.php', $filePath.$name, $fileName)); |
|
26 | + if( !empty( $name ) ) { |
|
27 | + $fileName = basename( $template ); |
|
28 | + $filePath = UtilityFacade::trimRight( $template, $fileName ); |
|
29 | + array_unshift( $templates, sprintf( '%s/%s.php', $filePath.$name, $fileName ) ); |
|
30 | 30 | } |
31 | - $templates = array_unique(apply_filters("castor/templates/$slug", $templates, $name)); |
|
32 | - $template = locate_template($templates); |
|
33 | - if (empty($template)) { |
|
34 | - if (file_exists("$slug.php")) { |
|
31 | + $templates = array_unique( apply_filters( "castor/templates/$slug", $templates, $name ) ); |
|
32 | + $template = locate_template( $templates ); |
|
33 | + if( empty( $template ) ) { |
|
34 | + if( file_exists( "$slug.php" ) ) { |
|
35 | 35 | return "$slug.php"; |
36 | 36 | } |
37 | - LogFacade::debug("$slug not found."); |
|
37 | + LogFacade::debug( "$slug not found." ); |
|
38 | 38 | } |
39 | 39 | return $template; |
40 | 40 | } |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function load($slug, $name = '') |
|
48 | + public function load( $slug, $name = '' ) |
|
49 | 49 | { |
50 | - if (!empty(($template = $this->get($slug, $name)))) { |
|
51 | - DevelopmentFacade::storeTemplatePath($template); |
|
52 | - load_template($template, false); |
|
50 | + if( !empty( ( $template = $this->get( $slug, $name ) ) ) ) { |
|
51 | + DevelopmentFacade::storeTemplatePath( $template ); |
|
52 | + load_template( $template, false ); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function main() |
60 | 60 | { |
61 | - $this->load($this->template); |
|
61 | + $this->load( $this->template ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return string|void |
68 | 68 | */ |
69 | - public function setLayout($template) |
|
69 | + public function setLayout( $template ) |
|
70 | 70 | { |
71 | - $template = str_replace(get_stylesheet_directory().'/templates/', '', $template); |
|
72 | - $this->template = UtilityFacade::trimRight($template, '.php'); |
|
73 | - return $this->get(apply_filters('castor/templates/layout', 'layouts/default')); |
|
71 | + $template = str_replace( get_stylesheet_directory().'/templates/', '', $template ); |
|
72 | + $this->template = UtilityFacade::trimRight( $template, '.php' ); |
|
73 | + return $this->get( apply_filters( 'castor/templates/layout', 'layouts/default' ) ); |
|
74 | 74 | } |
75 | 75 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | protected $image; |
22 | 22 | protected $video; |
23 | 23 | |
24 | - public function __construct(Gallery $gallery, Image $image, Video $video) |
|
24 | + public function __construct( Gallery $gallery, Image $image, Video $video ) |
|
25 | 25 | { |
26 | 26 | $this->gallery = $gallery; |
27 | 27 | $this->image = $image; |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | * @return string|void |
34 | 34 | * @throws BadMethodCallException |
35 | 35 | */ |
36 | - public function __call($name, array $args) |
|
36 | + public function __call( $name, array $args ) |
|
37 | 37 | { |
38 | - $mediaType = $this->validateMethod($name); |
|
39 | - $args = $this->validateArgs($args, $mediaType); |
|
38 | + $mediaType = $this->validateMethod( $name ); |
|
39 | + $args = $this->validateArgs( $args, $mediaType ); |
|
40 | 40 | |
41 | - if (str_replace($mediaType, '', strtolower($name))) { |
|
42 | - return $this->$mediaType->get($args[0])->$mediaType; |
|
41 | + if( str_replace( $mediaType, '', strtolower( $name ) ) ) { |
|
42 | + return $this->$mediaType->get( $args[0] )->$mediaType; |
|
43 | 43 | } |
44 | - return !empty($args[1]) |
|
45 | - ? $this->$mediaType->get($args[0])->render($args[1]) |
|
46 | - : $this->$mediaType->get($args[0])->render(); |
|
44 | + return !empty( $args[1] ) |
|
45 | + ? $this->$mediaType->get( $args[0] )->render( $args[1] ) |
|
46 | + : $this->$mediaType->get( $args[0] )->render(); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * @return mixed |
53 | 53 | * @throws BadMethodCallException |
54 | 54 | */ |
55 | - public function get($name, $args = []) |
|
55 | + public function get( $name, $args = [] ) |
|
56 | 56 | { |
57 | - $mediaType = $this->validateMethod($name); |
|
58 | - return $this->$mediaType->get($args)->$mediaType; |
|
57 | + $mediaType = $this->validateMethod( $name ); |
|
58 | + return $this->$mediaType->get( $args )->$mediaType; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | * @return array |
64 | 64 | * @throws BadMethodCallException |
65 | 65 | */ |
66 | - protected function validateArgs(array $args, $name) |
|
66 | + protected function validateArgs( array $args, $name ) |
|
67 | 67 | { |
68 | - if (!count($args) && 'image' == $name) { |
|
68 | + if( !count( $args ) && 'image' == $name ) { |
|
69 | 69 | $args[] = get_post_thumbnail_id(); |
70 | 70 | } |
71 | - if (count($args)) { |
|
71 | + if( count( $args ) ) { |
|
72 | 72 | return $args; |
73 | 73 | } |
74 | - throw new BadMethodCallException(sprintf('Missing arguments for: %s', $name)); |
|
74 | + throw new BadMethodCallException( sprintf( 'Missing arguments for: %s', $name ) ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | * @return string|false |
80 | 80 | * @throws BadMethodCallException |
81 | 81 | */ |
82 | - protected function validateMethod($name) |
|
82 | + protected function validateMethod( $name ) |
|
83 | 83 | { |
84 | - foreach ([$name, strtolower(substr($name, 3))] as $method) { |
|
85 | - if (property_exists($this, $method) && is_object($this->$method)) { |
|
84 | + foreach( [$name, strtolower( substr( $name, 3 ) )] as $method ) { |
|
85 | + if( property_exists( $this, $method ) && is_object( $this->$method ) ) { |
|
86 | 86 | return $method; |
87 | 87 | } |
88 | 88 | } |
89 | - throw new BadMethodCallException(sprintf('Not a valid method: %s', $name)); |
|
89 | + throw new BadMethodCallException( sprintf( 'Not a valid method: %s', $name ) ); |
|
90 | 90 | } |
91 | 91 | } |