@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | protected $args; |
| 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,9 +29,9 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * @return WP_Query |
| 31 | 31 | */ |
| 32 | - public function query( array $args = [] ) |
|
| 32 | + public function query(array $args = []) |
|
| 33 | 33 | { |
| 34 | - $this->normalizeArgs( $args ); |
|
| 34 | + $this->normalizeArgs($args); |
|
| 35 | 35 | |
| 36 | 36 | return new WP_Query([ |
| 37 | 37 | 'orderby' => 'post__in', |
@@ -47,21 +47,21 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return string |
| 49 | 49 | */ |
| 50 | - public function render( WP_Query $gallery ) |
|
| 50 | + public function render(WP_Query $gallery) |
|
| 51 | 51 | { |
| 52 | - $images = array_reduce( $gallery->posts, function( $images, $attachment ) { |
|
| 53 | - return $images . $this->renderImage( $attachment ); |
|
| 52 | + $images = array_reduce($gallery->posts, function($images, $attachment) { |
|
| 53 | + return $images . $this->renderImage($attachment); |
|
| 54 | 54 | }); |
| 55 | - return sprintf( '<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>', $images ); |
|
| 55 | + return sprintf('<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>', $images); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @return null|string |
| 60 | 60 | */ |
| 61 | - public function renderImage( WP_Post $attachment ) |
|
| 61 | + public function renderImage(WP_Post $attachment) |
|
| 62 | 62 | { |
| 63 | - $image = $this->image->get( $attachment->ID ); |
|
| 64 | - if( !$image )return; |
|
| 63 | + $image = $this->image->get($attachment->ID); |
|
| 64 | + if (!$image)return; |
|
| 65 | 65 | return sprintf( |
| 66 | 66 | '<figure class="gallery-image" data-w="%s" data-h="%s" data-ps=\'%s\' itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">' . |
| 67 | 67 | '%s<figcaption itemprop="caption description">' . |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | '</figure>', |
| 71 | 71 | $image->thumbnail['width'], |
| 72 | 72 | $image->thumbnail['height'], |
| 73 | - $this->getPhotoswipeData( $image ), |
|
| 74 | - $this->renderImageTag( $image ), |
|
| 73 | + $this->getPhotoswipeData($image), |
|
| 74 | + $this->renderImageTag($image), |
|
| 75 | 75 | $image->caption, |
| 76 | 76 | $image->copyright |
| 77 | 77 | ); |
@@ -80,15 +80,15 @@ discard block |
||
| 80 | 80 | /** |
| 81 | 81 | * @return null|string |
| 82 | 82 | */ |
| 83 | - public function renderPagination( WP_Query $query ) |
|
| 83 | + public function renderPagination(WP_Query $query) |
|
| 84 | 84 | { |
| 85 | - if( !$this->args['pagination'] )return; |
|
| 85 | + if (!$this->args['pagination'])return; |
|
| 86 | 86 | return paginate_links([ |
| 87 | - 'before_page_number' => '<span class="screen-reader-text">' . __( 'Page', 'castor' ) . ' </span>', |
|
| 87 | + 'before_page_number' => '<span class="screen-reader-text">' . __('Page', 'castor') . ' </span>', |
|
| 88 | 88 | 'current' => $query->query['paged'], |
| 89 | 89 | 'mid_size' => 1, |
| 90 | - 'next_text' => __( 'Next', 'castor' ), |
|
| 91 | - 'prev_text' => __( 'Previous', 'castor' ), |
|
| 90 | + 'next_text' => __('Next', 'castor'), |
|
| 91 | + 'prev_text' => __('Previous', 'castor'), |
|
| 92 | 92 | 'total' => $query->max_num_pages, |
| 93 | 93 | ]); |
| 94 | 94 | } |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return bool |
| 101 | 101 | */ |
| 102 | - protected function getBoolValue( $key, $value = null ) |
|
| 102 | + protected function getBoolValue($key, $value = null) |
|
| 103 | 103 | { |
| 104 | - $bool = $this->getValue( $key, $value ); |
|
| 104 | + $bool = $this->getValue($key, $value); |
|
| 105 | 105 | |
| 106 | - if( is_string( $bool ) && !in_array( $bool, ['true', 'false'] )) { |
|
| 107 | - $bool = wp_validate_boolean( $this->postmeta->get( $bool )); |
|
| 106 | + if (is_string($bool) && !in_array($bool, ['true', 'false'])) { |
|
| 107 | + $bool = wp_validate_boolean($this->postmeta->get($bool)); |
|
| 108 | 108 | } |
| 109 | - return is_bool( $bool ) |
|
| 109 | + return is_bool($bool) |
|
| 110 | 110 | ? $bool |
| 111 | 111 | : false; |
| 112 | 112 | } |
@@ -116,15 +116,15 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return int |
| 118 | 118 | */ |
| 119 | - protected function getGalleryArg( $value = null ) |
|
| 119 | + protected function getGalleryArg($value = null) |
|
| 120 | 120 | { |
| 121 | - $gallery = $this->getValue( 'gallery', $value ); |
|
| 121 | + $gallery = $this->getValue('gallery', $value); |
|
| 122 | 122 | |
| 123 | - if( !is_numeric( $gallery ) && is_string( $gallery )) { |
|
| 124 | - $gallery = intval( $this->postmeta->get( $gallery )); |
|
| 123 | + if (!is_numeric($gallery) && is_string($gallery)) { |
|
| 124 | + $gallery = intval($this->postmeta->get($gallery)); |
|
| 125 | 125 | } |
| 126 | - return !is_null( get_post( $gallery )) |
|
| 127 | - ? intval( $gallery ) |
|
| 126 | + return !is_null(get_post($gallery)) |
|
| 127 | + ? intval($gallery) |
|
| 128 | 128 | : 0; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @return int |
| 135 | 135 | */ |
| 136 | - protected function getImagesPerPageArg( $value = null ) |
|
| 136 | + protected function getImagesPerPageArg($value = null) |
|
| 137 | 137 | { |
| 138 | - $perPage = $this->getValue( 'images_per_page', $value ); |
|
| 138 | + $perPage = $this->getValue('images_per_page', $value); |
|
| 139 | 139 | |
| 140 | - if( !is_numeric( $perPage ) && is_string( $perPage )) { |
|
| 141 | - $perPage = $this->postmeta->get( $perPage ); |
|
| 140 | + if (!is_numeric($perPage) && is_string($perPage)) { |
|
| 141 | + $perPage = $this->postmeta->get($perPage); |
|
| 142 | 142 | } |
| 143 | - return !!intval( $perPage ) |
|
| 143 | + return !!intval($perPage) |
|
| 144 | 144 | ? $perPage |
| 145 | 145 | : -1; |
| 146 | 146 | } |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | - protected function getLazyloadArg( $value = null ) |
|
| 153 | + protected function getLazyloadArg($value = null) |
|
| 154 | 154 | { |
| 155 | - return $this->getBoolValue( 'lazyload', $value ); |
|
| 155 | + return $this->getBoolValue('lazyload', $value); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -160,18 +160,18 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | - protected function getMediaArg( $value = null ) |
|
| 163 | + protected function getMediaArg($value = null) |
|
| 164 | 164 | { |
| 165 | - $media = $this->getValue( 'media', $value ); |
|
| 165 | + $media = $this->getValue('media', $value); |
|
| 166 | 166 | |
| 167 | - if( is_string( $media )) { |
|
| 168 | - $media = $this->postmeta->get( $media, [ |
|
| 167 | + if (is_string($media)) { |
|
| 168 | + $media = $this->postmeta->get($media, [ |
|
| 169 | 169 | 'ID' => $this->getGalleryArg(), |
| 170 | 170 | 'single' => false, |
| 171 | 171 | ]); |
| 172 | 172 | } |
| 173 | - return is_array( $media ) |
|
| 174 | - ? wp_parse_id_list( $media ) |
|
| 173 | + return is_array($media) |
|
| 174 | + ? wp_parse_id_list($media) |
|
| 175 | 175 | : []; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | protected function getPaged() |
| 182 | 182 | { |
| 183 | - return intval( get_query_var(( is_front_page() ? 'page' : 'paged' ))) ?: 1; |
|
| 183 | + return intval(get_query_var((is_front_page() ? 'page' : 'paged'))) ?: 1; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | * |
| 189 | 189 | * @return bool |
| 190 | 190 | */ |
| 191 | - protected function getPaginationArg( $value = null ) |
|
| 191 | + protected function getPaginationArg($value = null) |
|
| 192 | 192 | { |
| 193 | - return $this->getBoolValue( 'pagination', $value ); |
|
| 193 | + return $this->getBoolValue('pagination', $value); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -198,17 +198,17 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @return bool |
| 200 | 200 | */ |
| 201 | - protected function getPermalinksArg( $value = null ) |
|
| 201 | + protected function getPermalinksArg($value = null) |
|
| 202 | 202 | { |
| 203 | - return $this->getBoolValue( 'permalinks', $value ); |
|
| 203 | + return $this->getBoolValue('permalinks', $value); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | - protected function getPhotoswipeData( $image ) |
|
| 209 | + protected function getPhotoswipeData($image) |
|
| 210 | 210 | { |
| 211 | - return sprintf( '{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
| 211 | + return sprintf('{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
| 212 | 212 | $image->large['url'], |
| 213 | 213 | $image->large['width'], |
| 214 | 214 | $image->large['height'], |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | * |
| 225 | 225 | * @return mixed |
| 226 | 226 | */ |
| 227 | - protected function getValue( $key, $value = null ) |
|
| 227 | + protected function getValue($key, $value = null) |
|
| 228 | 228 | { |
| 229 | - if( is_null( $value ) && isset( $this->args[$key] )) { |
|
| 229 | + if (is_null($value) && isset($this->args[$key])) { |
|
| 230 | 230 | $value = $this->args[$key]; |
| 231 | 231 | } |
| 232 | 232 | return $value; |
@@ -235,23 +235,23 @@ discard block |
||
| 235 | 235 | /** |
| 236 | 236 | * @return array |
| 237 | 237 | */ |
| 238 | - protected function normalizeArgs( array $args = [] ) |
|
| 238 | + protected function normalizeArgs(array $args = []) |
|
| 239 | 239 | { |
| 240 | 240 | $defaults = [ |
| 241 | - 'gallery', // (string) meta_key | (int) post_id |
|
| 242 | - 'lazyload', // (string) meta_key | (bool) |
|
| 243 | - 'media', // (string) meta_key | (array) post_ids |
|
| 244 | - 'pagination', // (string) meta_key | (bool) |
|
| 241 | + 'gallery', // (string) meta_key | (int) post_id |
|
| 242 | + 'lazyload', // (string) meta_key | (bool) |
|
| 243 | + 'media', // (string) meta_key | (array) post_ids |
|
| 244 | + 'pagination', // (string) meta_key | (bool) |
|
| 245 | 245 | 'images_per_page', // (string) meta_key | (int) number |
| 246 | - 'permalinks', // (string) meta_key | (bool) |
|
| 246 | + 'permalinks', // (string) meta_key | (bool) |
|
| 247 | 247 | ]; |
| 248 | 248 | |
| 249 | - $this->args = shortcode_atts( array_combine( $defaults, $defaults ), $args ); |
|
| 249 | + $this->args = shortcode_atts(array_combine($defaults, $defaults), $args); |
|
| 250 | 250 | |
| 251 | - array_walk( $this->args, function( &$value, $key ) { |
|
| 252 | - $method = $this->utility->buildMethodName( $key . '_arg' ); |
|
| 253 | - if( method_exists( $this, $method )) { |
|
| 254 | - $value = call_user_func([ $this, $method ], $value ); |
|
| 251 | + array_walk($this->args, function(&$value, $key) { |
|
| 252 | + $method = $this->utility->buildMethodName($key . '_arg'); |
|
| 253 | + if (method_exists($this, $method)) { |
|
| 254 | + $value = call_user_func([$this, $method], $value); |
|
| 255 | 255 | } |
| 256 | 256 | }); |
| 257 | 257 | |
@@ -263,20 +263,20 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @return null|string |
| 265 | 265 | */ |
| 266 | - protected function renderImageTag( $image ) |
|
| 266 | + protected function renderImageTag($image) |
|
| 267 | 267 | { |
| 268 | 268 | $imgSrc = $this->getLazyloadArg() |
| 269 | - ? $this->theme->imageUri( 'blank.gif' ) |
|
| 269 | + ? $this->theme->imageUri('blank.gif') |
|
| 270 | 270 | : $image->thumbnail['url']; |
| 271 | 271 | |
| 272 | - $imgTag = sprintf( '<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
| 272 | + $imgTag = sprintf('<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
| 273 | 273 | $imgSrc, |
| 274 | 274 | $image->thumbnail['url'], |
| 275 | 275 | $image->alt |
| 276 | 276 | ); |
| 277 | 277 | |
| 278 | 278 | return $this->getPermalinksArg() |
| 279 | - ? sprintf( '<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag ) |
|
| 279 | + ? sprintf('<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag) |
|
| 280 | 280 | : $imgTag; |
| 281 | 281 | } |
| 282 | 282 | } |