Completed
Push — develop ( 2c713a...483098 )
by Paul
02:05
created
src/Gallery.php 2 patches
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	protected $theme;
20 20
 	protected $utility;
21 21
 
22
-	public function __construct( Image $image, PostMeta $postmeta, Theme $theme, Utility $utility )
22
+	public function __construct(Image $image, PostMeta $postmeta, Theme $theme, Utility $utility)
23 23
 	{
24 24
 		$this->image    = $image;
25 25
 		$this->postmeta = $postmeta;
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 	/**
31 31
 	 * @return WP_Query
32 32
 	 */
33
-	public function get( array $args = [] )
33
+	public function get(array $args = [])
34 34
 	{
35
-		$this->normalizeArgs( $args );
35
+		$this->normalizeArgs($args);
36 36
 
37 37
 		$this->gallery = new WP_Query([
38 38
 			'orderby'        => 'post__in',
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function render()
54 54
 	{
55
-		if( empty( $this->args['media'] ))return;
56
-		$images = array_reduce( $this->gallery->posts, function( $images, $attachment ) {
57
-			return $images . $this->renderImage( $attachment );
55
+		if (empty($this->args['media']))return;
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
 block discarded – undo
65 65
 	/**
66 66
 	 * @return null|string
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 )return;
72
+		if (!$image)return;
73 73
 		return sprintf(
74 74
 			'<figure class="gallery-image" data-w="%s" data-h="%s" data-ps=\'%s\' itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">' .
75 75
 				'%s<figcaption itemprop="caption description">' .
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 			'</figure>',
79 79
 			$image->thumbnail['width'],
80 80
 			$image->thumbnail['height'],
81
-			$this->getPhotoswipeData( $image ),
82
-			$this->renderImageTag( $image ),
81
+			$this->getPhotoswipeData($image),
82
+			$this->renderImageTag($image),
83 83
 			$image->caption,
84 84
 			$image->copyright
85 85
 		);
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function renderPagination()
92 92
 	{
93
-		if( !$this->args['pagination'] )return;
93
+		if (!$this->args['pagination'])return;
94 94
 		return paginate_links([
95
-			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page', 'castor' ) . ' </span>',
95
+			'before_page_number' => '<span class="screen-reader-text">' . __('Page', 'castor') . ' </span>',
96 96
 			'current'            => $this->gallery->query['paged'],
97 97
 			'mid_size'           => 1,
98
-			'next_text'          => __( 'Next', 'castor' ),
99
-			'prev_text'          => __( 'Previous', 'castor' ),
98
+			'next_text'          => __('Next', 'castor'),
99
+			'prev_text'          => __('Previous', 'castor'),
100 100
 			'total'              => $this->gallery->max_num_pages,
101 101
 		]);
102 102
 	}
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 	 *
108 108
 	 * @return bool
109 109
 	 */
110
-	protected function getBoolValue( $key, $value = null )
110
+	protected function getBoolValue($key, $value = null)
111 111
 	{
112
-		$bool = $this->getValue( $key, $value );
112
+		$bool = $this->getValue($key, $value);
113 113
 
114
-		if( is_null( filter_var( $bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ))) {
115
-			$bool = $this->postmeta->get( $bool );
114
+		if (is_null(filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))) {
115
+			$bool = $this->postmeta->get($bool);
116 116
 		}
117
-		return wp_validate_boolean( $bool );
117
+		return wp_validate_boolean($bool);
118 118
 	}
119 119
 
120 120
 	/**
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @return int
124 124
 	 */
125
-	protected function getGalleryArg( $value = null )
125
+	protected function getGalleryArg($value = null)
126 126
 	{
127
-		$gallery = $this->getValue( 'gallery', $value );
127
+		$gallery = $this->getValue('gallery', $value);
128 128
 
129
-		if( !is_numeric( $gallery ) && is_string( $gallery )) {
130
-			$gallery = intval( $this->postmeta->get( $gallery ));
129
+		if (!is_numeric($gallery) && is_string($gallery)) {
130
+			$gallery = intval($this->postmeta->get($gallery));
131 131
 		}
132
-		return !is_null( get_post( $gallery ))
133
-			? intval( $gallery )
132
+		return !is_null(get_post($gallery))
133
+			? intval($gallery)
134 134
 			: 0;
135 135
 	}
136 136
 
@@ -139,14 +139,14 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return int
141 141
 	 */
142
-	protected function getImagesPerPageArg( $value = null )
142
+	protected function getImagesPerPageArg($value = null)
143 143
 	{
144
-		$perPage = $this->getValue( 'images_per_page', $value );
144
+		$perPage = $this->getValue('images_per_page', $value);
145 145
 
146
-		if( !is_numeric( $perPage ) && is_string( $perPage )) {
147
-			$perPage = $this->postmeta->get( $perPage );
146
+		if (!is_numeric($perPage) && is_string($perPage)) {
147
+			$perPage = $this->postmeta->get($perPage);
148 148
 		}
149
-		return !!intval( $perPage )
149
+		return !!intval($perPage)
150 150
 			? $perPage
151 151
 			: -1;
152 152
 	}
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 	 *
157 157
 	 * @return bool
158 158
 	 */
159
-	protected function getLazyloadArg( $value = null )
159
+	protected function getLazyloadArg($value = null)
160 160
 	{
161
-		return $this->getBoolValue( 'lazyload', $value );
161
+		return $this->getBoolValue('lazyload', $value);
162 162
 	}
163 163
 
164 164
 	/**
@@ -166,18 +166,18 @@  discard block
 block discarded – undo
166 166
 	 *
167 167
 	 * @return array
168 168
 	 */
169
-	protected function getMediaArg( $value = null )
169
+	protected function getMediaArg($value = null)
170 170
 	{
171
-		$media = $this->getValue( 'media', $value );
171
+		$media = $this->getValue('media', $value);
172 172
 
173
-		if( is_string( $media )) {
174
-			$media = $this->postmeta->get( $media, [
173
+		if (is_string($media)) {
174
+			$media = $this->postmeta->get($media, [
175 175
 				'ID'     => $this->getGalleryArg(),
176 176
 				'single' => false,
177 177
 			]);
178 178
 		}
179
-		return is_array( $media )
180
-			? wp_parse_id_list( $media )
179
+		return is_array($media)
180
+			? wp_parse_id_list($media)
181 181
 			: [];
182 182
 	}
183 183
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	protected function getPaged()
188 188
 	{
189
-		return intval( get_query_var(( is_front_page() ? 'page' : 'paged' ))) ?: 1;
189
+		return intval(get_query_var((is_front_page() ? 'page' : 'paged'))) ?: 1;
190 190
 	}
191 191
 
192 192
 	/**
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 	 *
195 195
 	 * @return bool
196 196
 	 */
197
-	protected function getPaginationArg( $value = null )
197
+	protected function getPaginationArg($value = null)
198 198
 	{
199
-		return $this->getBoolValue( 'pagination', $value );
199
+		return $this->getBoolValue('pagination', $value);
200 200
 	}
201 201
 
202 202
 	/**
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
 	 *
205 205
 	 * @return bool
206 206
 	 */
207
-	protected function getPermalinksArg( $value = null )
207
+	protected function getPermalinksArg($value = null)
208 208
 	{
209
-		return $this->getBoolValue( 'permalinks', $value );
209
+		return $this->getBoolValue('permalinks', $value);
210 210
 	}
211 211
 
212 212
 	/**
213 213
 	 * @return string
214 214
 	 */
215
-	protected function getPhotoswipeData( $image )
215
+	protected function getPhotoswipeData($image)
216 216
 	{
217
-		return sprintf( '{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}',
217
+		return sprintf('{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}',
218 218
 			$image->large['url'],
219 219
 			$image->large['width'],
220 220
 			$image->large['height'],
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 	 *
231 231
 	 * @return mixed
232 232
 	 */
233
-	protected function getValue( $key, $value = null )
233
+	protected function getValue($key, $value = null)
234 234
 	{
235
-		if( is_null( $value ) && isset( $this->args[$key] )) {
235
+		if (is_null($value) && isset($this->args[$key])) {
236 236
 			$value = $this->args[$key];
237 237
 		}
238 238
 		return $value;
@@ -241,23 +241,23 @@  discard block
 block discarded – undo
241 241
 	/**
242 242
 	 * @return array
243 243
 	 */
244
-	protected function normalizeArgs( array $args = [] )
244
+	protected function normalizeArgs(array $args = [])
245 245
 	{
246 246
 		$defaults = [
247
-			'gallery',         // (string) meta_key | (int) post_id
248
-			'lazyload',        // (string) meta_key | (bool)
249
-			'media',           // (string) meta_key | (array) post_ids
250
-			'pagination',      // (string) meta_key | (bool)
247
+			'gallery', // (string) meta_key | (int) post_id
248
+			'lazyload', // (string) meta_key | (bool)
249
+			'media', // (string) meta_key | (array) post_ids
250
+			'pagination', // (string) meta_key | (bool)
251 251
 			'images_per_page', // (string) meta_key | (int) number
252
-			'permalinks',      // (string) meta_key | (bool)
252
+			'permalinks', // (string) meta_key | (bool)
253 253
 		];
254 254
 
255
-		$this->args = shortcode_atts( array_combine( $defaults, $defaults ), $args );
255
+		$this->args = shortcode_atts(array_combine($defaults, $defaults), $args);
256 256
 
257
-		array_walk( $this->args, function( &$value, $key ) {
258
-			$method = $this->utility->buildMethodName( $key . '_arg' );
259
-			if( method_exists( $this, $method )) {
260
-				$value = call_user_func([ $this, $method ], $value );
257
+		array_walk($this->args, function(&$value, $key) {
258
+			$method = $this->utility->buildMethodName($key . '_arg');
259
+			if (method_exists($this, $method)) {
260
+				$value = call_user_func([$this, $method], $value);
261 261
 			}
262 262
 		});
263 263
 
@@ -269,20 +269,20 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return null|string
271 271
 	 */
272
-	protected function renderImageTag( $image )
272
+	protected function renderImageTag($image)
273 273
 	{
274 274
 		$imgSrc = $this->getLazyloadArg()
275
-			? $this->theme->imageUri( 'blank.gif' )
275
+			? $this->theme->imageUri('blank.gif')
276 276
 			: $image->thumbnail['url'];
277 277
 
278
-		$imgTag = sprintf( '<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>',
278
+		$imgTag = sprintf('<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>',
279 279
 			$imgSrc,
280 280
 			$image->thumbnail['url'],
281 281
 			$image->alt
282 282
 		);
283 283
 
284 284
 		return $this->getPermalinksArg()
285
-			? sprintf( '<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag )
285
+			? sprintf('<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag)
286 286
 			: $imgTag;
287 287
 	}
288 288
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function render()
54 54
 	{
55
-		if( empty( $this->args['media'] ))return;
55
+		if( empty( $this->args['media'] )) {
56
+			return;
57
+		}
56 58
 		$images = array_reduce( $this->gallery->posts, function( $images, $attachment ) {
57 59
 			return $images . $this->renderImage( $attachment );
58 60
 		});
@@ -69,7 +71,9 @@  discard block
 block discarded – undo
69 71
 	{
70 72
 		$image = $this->image->get( $attachment->ID )->image;
71 73
 
72
-		if( !$image )return;
74
+		if( !$image ) {
75
+			return;
76
+		}
73 77
 		return sprintf(
74 78
 			'<figure class="gallery-image" data-w="%s" data-h="%s" data-ps=\'%s\' itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">' .
75 79
 				'%s<figcaption itemprop="caption description">' .
@@ -90,7 +94,9 @@  discard block
 block discarded – undo
90 94
 	 */
91 95
 	public function renderPagination()
92 96
 	{
93
-		if( !$this->args['pagination'] )return;
97
+		if( !$this->args['pagination'] ) {
98
+			return;
99
+		}
94 100
 		return paginate_links([
95 101
 			'before_page_number' => '<span class="screen-reader-text">' . __( 'Page', 'castor' ) . ' </span>',
96 102
 			'current'            => $this->gallery->query['paged'],
Please login to merge, or discard this patch.
src/Helpers/Template.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -18,24 +18,24 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return string
20 20
 	 */
21
-	public function get( $slug, $name = '' )
21
+	public function get($slug, $name = '')
22 22
 	{
23
-		$template  = Utility::startWith( 'templates/', $slug );
23
+		$template  = Utility::startWith('templates/', $slug);
24 24
 		$templates = ["{$template}.php"];
25 25
 
26
-		if( 'index' != basename( $this->template, '.php' )) {
27
-			$filepath = dirname( $template ) != '.'
28
-				? sprintf( '%s/', dirname( $template ))
26
+		if ('index' != basename($this->template, '.php')) {
27
+			$filepath = dirname($template) != '.'
28
+				? sprintf('%s/', dirname($template))
29 29
 				: '';
30 30
 			array_unshift(
31 31
 				$templates,
32
-				sprintf( '%s%s-%s.php', $filepath, $name, basename( $template ))
32
+				sprintf('%s%s-%s.php', $filepath, $name, basename($template))
33 33
 			);
34 34
 		}
35 35
 
36
-		$templates = apply_filters( "castor/templates/{$slug}", $templates, $name );
36
+		$templates = apply_filters("castor/templates/{$slug}", $templates, $name);
37 37
 
38
-		return locate_template( $templates );
38
+		return locate_template($templates);
39 39
 	}
40 40
 
41 41
 	/**
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return void
46 46
 	 */
47
-	public function load( $slug, $name = '' )
47
+	public function load($slug, $name = '')
48 48
 	{
49
-		$template = $this->get( $slug, $name );
50
-		if( !empty( $template )) {
51
-			Development::storeTemplatePath( $template );
52
-			load_template( $template, false );
49
+		$template = $this->get($slug, $name);
50
+		if (!empty($template)) {
51
+			Development::storeTemplatePath($template);
52
+			load_template($template, false);
53 53
 		}
54 54
 	}
55 55
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
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,9 +66,9 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @return string|void
68 68
 	 */
69
-	public function setLayout( $template )
69
+	public function setLayout($template)
70 70
 	{
71
-		$this->template = Utility::trimRight( strstr( $template, 'templates/' ), '.php' );
72
-		return $this->get( apply_filters( 'castor/templates/layout', 'layouts/default' ));
71
+		$this->template = Utility::trimRight(strstr($template, 'templates/'), '.php');
72
+		return $this->get(apply_filters('castor/templates/layout', 'layouts/default'));
73 73
 	}
74 74
 }
Please login to merge, or discard this patch.