Completed
Push — master ( 75c234...bb087c )
by Andrew
03:53
created
app/classy/classy-template.php 4 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * Returns template name for render, based on type of request
53 53
 	 * 
54 54
 	 * @param  string $type 
55
-	 * @return array 
55
+	 * @return string|false 
56 56
 	 */
57 57
 	public static function get_available_template($type) {
58 58
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * Returns list of templates to check, based on type of request
88 88
 	 * 
89 89
 	 * @param  string $type 
90
-	 * @return array
90
+	 * @return string[]
91 91
 	 */
92 92
 	private static function get_request_templates_list($type) {
93 93
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	/**
285 285
 	 * Returns classy template name or boolean if this is not classy template
286 286
 	 * 
287
-	 * @return mixed
287
+	 * @return string|false
288 288
 	 */
289 289
 	public static function get_classy_template() {
290 290
 
@@ -373,6 +373,7 @@  discard block
 block discarded – undo
373 373
 	/**
374 374
 	 * Returns available template, based on page argument
375 375
 	 * 
376
+	 * @param string $page
376 377
 	 * @return string
377 378
 	 */
378 379
 	public static function get_blade_template($page = null) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -445,7 +445,7 @@
 block discarded – undo
445 445
 
446 446
 		$templates = array();
447 447
 		
448
-	    $files = (array) glob( THEME_PATH . '/' . self::$theme_templates_folder . '/*/*.blade.php' );
448
+		$files = (array) glob( THEME_PATH . '/' . self::$theme_templates_folder . '/*/*.blade.php' );
449 449
 
450 450
 		foreach ( $files as $filename ) {
451 451
 			
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
 		$template = str_replace('.', '/', $template);
31 31
 
32
-		return THEME_PATH . self::$theme_templates_folder . '/' . $template . '.blade.php';			
32
+		return THEME_PATH.self::$theme_templates_folder.'/'.$template.'.blade.php';			
33 33
 
34 34
 	}
35 35
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
 		// Classy template?
60 60
 
61
-		if ( $template = self::get_classy_template() ) {
61
+		if ($template = self::get_classy_template()) {
62 62
 		
63 63
 			return $template;
64 64
 		
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 		foreach ($templates as $template) {
72 72
 
73
-			if ( self::template_exists($template) ):
73
+			if (self::template_exists($template)):
74 74
 
75 75
 				return $template;
76 76
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 
97 97
 		// Home
98 98
 
99
-		if ( $type == 'home' ) :
99
+		if ($type == 'home') :
100 100
 
101 101
 			$templates[] = 'home';
102 102
 			$templates[] = 'index';
@@ -104,32 +104,32 @@  discard block
 block discarded – undo
104 104
 
105 105
 		// Single
106 106
 
107
-		elseif ( $type == 'single' ) :
107
+		elseif ($type == 'single') :
108 108
 
109
-			$post_type = get_query_var( 'post_type' );
109
+			$post_type = get_query_var('post_type');
110 110
 
111
-			$templates[] = 'single-' . $post_type;
111
+			$templates[] = 'single-'.$post_type;
112 112
 
113 113
 			$templates[] = 'single';
114 114
 
115 115
 		// Post type
116 116
 
117
-		elseif ( $type == 'post_type_archive' ) :
117
+		elseif ($type == 'post_type_archive') :
118 118
 
119
-			$post_type = get_query_var( 'post_type' );
119
+			$post_type = get_query_var('post_type');
120 120
 
121
-			$templates[] = 'archive-' . $post_type;
121
+			$templates[] = 'archive-'.$post_type;
122 122
 
123 123
 			$templates[] = 'archive';
124 124
 
125 125
 
126 126
 		// Taxonomy
127 127
 
128
-		elseif ( $type == 'taxonomy' ):
128
+		elseif ($type == 'taxonomy'):
129 129
 
130 130
 			$term = get_queried_object();
131 131
 
132
-			if ( ! empty( $term->slug ) ) {
132
+			if (!empty($term->slug)) {
133 133
 				
134 134
 				$taxonomy = $term->taxonomy;
135 135
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 
143 143
 		// Category
144 144
 
145
-		elseif ( $type == 'category' ):
145
+		elseif ($type == 'category'):
146 146
 
147 147
 			$category = get_queried_object();
148 148
 
149
-			if ( ! empty( $category->slug ) ) {
149
+			if (!empty($category->slug)) {
150 150
 				$templates[] = "category-{$category->slug}";
151 151
 				$templates[] = "category-{$category->term_id}";
152 152
 			}
@@ -155,23 +155,23 @@  discard block
 block discarded – undo
155 155
 
156 156
 		// Attachment
157 157
 
158
-		elseif ( $type == 'attachment' ):
158
+		elseif ($type == 'attachment'):
159 159
 
160 160
 			$attachment = get_queried_object();
161 161
 
162
-			if ( $attachment ) {
162
+			if ($attachment) {
163 163
 
164
-				if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
164
+				if (false !== strpos($attachment->post_mime_type, '/')) {
165 165
 				
166
-					list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
166
+					list($type, $subtype) = explode('/', $attachment->post_mime_type);
167 167
 				
168 168
 				} else {
169 169
 				
170
-					list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
170
+					list($type, $subtype) = array($attachment->post_mime_type, '');
171 171
 				
172 172
 				}
173 173
 
174
-				if ( ! empty( $subtype ) ) {
174
+				if (!empty($subtype)) {
175 175
 					$templates[] = "{$type}-{$subtype}";
176 176
 					$templates[] = "{$subtype}";
177 177
 				}
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 
184 184
 		// Tag
185 185
 
186
-		elseif ( $type == 'tag' ):
186
+		elseif ($type == 'tag'):
187 187
 
188 188
 			$tag = get_queried_object();
189 189
 
190
-			if ( ! empty( $tag->slug ) ) {
190
+			if (!empty($tag->slug)) {
191 191
 				$templates[] = "tag-{$tag->slug}";
192 192
 				$templates[] = "tag-{$tag->term_id}";
193 193
 			}
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 
197 197
 		// Author
198 198
 
199
-		elseif ( $type == 'author' ):
199
+		elseif ($type == 'author'):
200 200
 
201 201
 			$author = get_queried_object();
202 202
 
203
-			if ( $author instanceof WP_User ) {
203
+			if ($author instanceof WP_User) {
204 204
 				$templates[] = "author-{$author->user_nicename}";
205 205
 				$templates[] = "author-{$author->ID}";
206 206
 			}
@@ -209,32 +209,32 @@  discard block
 block discarded – undo
209 209
 
210 210
 		// Front Page
211 211
 
212
-		elseif ( $type == 'front-page' ):
212
+		elseif ($type == 'front-page'):
213 213
 
214 214
 			$id = get_queried_object_id();
215 215
 
216 216
 			$pagename = get_query_var('pagename');
217 217
 
218
-			if ( ! $pagename && $id ) {
218
+			if (!$pagename && $id) {
219 219
 				// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
220 220
 				$post = get_queried_object();
221
-				if ( $post )
221
+				if ($post)
222 222
 					$pagename = $post->post_name;
223 223
 			}
224 224
 
225 225
 			$template = get_post_meta('theme-page-template', $id);
226 226
 
227
-			if ( $template != 'index' )
227
+			if ($template != 'index')
228 228
 				$templates[] = $template;
229
-			if ( $pagename )
229
+			if ($pagename)
230 230
 				$templates[] = "page-$pagename";
231
-			if ( $id )
231
+			if ($id)
232 232
 				$templates[] = "page-$id";
233 233
 			$templates[] = '';
234 234
 
235 235
 		// Page
236 236
 
237
-		elseif ( $type == 'page' ):
237
+		elseif ($type == 'page'):
238 238
 
239 239
 			$id = get_queried_object_id();
240 240
 			
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
 
243 243
 			$pagename = get_query_var('pagename');
244 244
 
245
-			if ( ! $pagename && $id ) {
245
+			if (!$pagename && $id) {
246 246
 				// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
247 247
 				$post = get_queried_object();
248
-				if ( $post )
248
+				if ($post)
249 249
 					$pagename = $post->post_name;
250 250
 			}
251 251
 
252
-			if ( $template != 'index' )
252
+			if ($template != 'index')
253 253
 				$templates[] = $template;
254
-			if ( $pagename )
254
+			if ($pagename)
255 255
 				$templates[] = "page-$pagename";
256
-			if ( $id )
256
+			if ($id)
257 257
 				$templates[] = "page-$id";
258 258
 			$templates[] = 'page';
259 259
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 
293 293
 		preg_match('/classy\-(.*)/', $template_slug, $matches);
294 294
 
295
-		if ( $matches && isset($matches[1]) ) return $matches[1];
295
+		if ($matches && isset($matches[1])) return $matches[1];
296 296
 
297 297
 		return false;
298 298
 
@@ -306,37 +306,37 @@  discard block
 block discarded – undo
306 306
 	 */
307 307
 	public static function get_current_page() {
308 308
 
309
-		if ( is_404() && $template = self::get_available_template('404') ) :
309
+		if (is_404() && $template = self::get_available_template('404')) :
310 310
 
311
-		elseif ( is_search() && $template = self::get_available_template('search') ) :
311
+		elseif (is_search() && $template = self::get_available_template('search')) :
312 312
 
313
-		elseif ( is_front_page() && $template = self::get_available_template('front-page') ) :
313
+		elseif (is_front_page() && $template = self::get_available_template('front-page')) :
314 314
 
315
-		elseif ( is_home() && $template = self::get_available_template('home') ) :
315
+		elseif (is_home() && $template = self::get_available_template('home')) :
316 316
 
317
-		elseif ( is_post_type_archive() && $template = self::get_available_template('post_type_archive') ) :
317
+		elseif (is_post_type_archive() && $template = self::get_available_template('post_type_archive')) :
318 318
 
319
-		elseif ( is_tax() && $template = self::get_available_template('taxonomy') ) :
319
+		elseif (is_tax() && $template = self::get_available_template('taxonomy')) :
320 320
 
321
-		elseif ( is_attachment() && $template = self::get_available_template('attachment') ) :
321
+		elseif (is_attachment() && $template = self::get_available_template('attachment')) :
322 322
 
323
-		elseif ( is_single() && $template = self::get_available_template('single') ) :
323
+		elseif (is_single() && $template = self::get_available_template('single')) :
324 324
 
325
-		elseif ( is_page() && $template = self::get_available_template('page') ) :
325
+		elseif (is_page() && $template = self::get_available_template('page')) :
326 326
 
327
-		elseif ( is_singular() && $template = self::get_available_template('singular') ) :
327
+		elseif (is_singular() && $template = self::get_available_template('singular')) :
328 328
 
329
-		elseif ( is_category() && $template = self::get_available_template('category') ) :
329
+		elseif (is_category() && $template = self::get_available_template('category')) :
330 330
 
331
-		elseif ( is_tag() && $template = self::get_available_template('tag') ) :
331
+		elseif (is_tag() && $template = self::get_available_template('tag')) :
332 332
 
333
-		elseif ( is_author() && $template = self::get_available_template('author') ) :
333
+		elseif (is_author() && $template = self::get_available_template('author')) :
334 334
 
335
-		elseif ( is_date() && $template = self::get_available_template('date') ) :
335
+		elseif (is_date() && $template = self::get_available_template('date')) :
336 336
 
337
-		elseif ( is_archive() && $template = self::get_available_template('archive') ) :
337
+		elseif (is_archive() && $template = self::get_available_template('archive')) :
338 338
 
339
-		elseif ( is_paged() && $template = self::get_available_template('paged') ) :
339
+		elseif (is_paged() && $template = self::get_available_template('paged')) :
340 340
 
341 341
 		else :
342 342
 		
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 
364 364
 		} else {
365 365
 
366
-			return $template . '.' . $template;
366
+			return $template.'.'.$template;
367 367
 			
368 368
 		}
369 369
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	 */
405 405
 	public static function render($template = null, $data = null) {
406 406
 
407
-		$views = THEME_PATH . self::$theme_templates_folder;
408
-		$cache = WP_CONTENT_DIR . '/templatecache';
407
+		$views = THEME_PATH.self::$theme_templates_folder;
408
+		$cache = WP_CONTENT_DIR.'/templatecache';
409 409
 		$common_scope = ClassyScope::get_common_scope();
410 410
 
411 411
 		if ($template !== null && is_string($template)) {
@@ -445,19 +445,19 @@  discard block
 block discarded – undo
445 445
 
446 446
 		$templates = array();
447 447
 		
448
-	    $files = (array) glob( THEME_PATH . '/' . self::$theme_templates_folder . '/*/*.blade.php' );
448
+	    $files = (array) glob(THEME_PATH.'/'.self::$theme_templates_folder.'/*/*.blade.php');
449 449
 
450
-		foreach ( $files as $filename ) {
450
+		foreach ($files as $filename) {
451 451
 			
452
-			if ( !empty($filename) ) {
452
+			if (!empty($filename)) {
453 453
 
454
-				if ( ! preg_match( '/\{\{\-\-\s*Template Name:(.*)\s*\-\-\}\}/mi', file_get_contents( $filename ), $header ) ) continue;
454
+				if (!preg_match('/\{\{\-\-\s*Template Name:(.*)\s*\-\-\}\}/mi', file_get_contents($filename), $header)) continue;
455 455
 
456 456
 				$template_name = trim($header[1]);
457 457
 
458 458
 				preg_match('/\/([^\/]*)\.blade.php$/is', $filename, $filename_match);
459 459
 
460
-				$template_file = 'classy-' . $filename_match[1];
460
+				$template_file = 'classy-'.$filename_match[1];
461 461
 
462 462
 				$templates[$template_file] = $template_name;
463 463
 				
Please login to merge, or discard this patch.
Braces   +44 added lines, -24 removed lines patch added patch discarded remove patch
@@ -165,7 +165,8 @@  discard block
 block discarded – undo
165 165
 				
166 166
 					list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
167 167
 				
168
-				} else {
168
+				}
169
+				else {
169 170
 				
170 171
 					list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
171 172
 				
@@ -218,18 +219,22 @@  discard block
 block discarded – undo
218 219
 			if ( ! $pagename && $id ) {
219 220
 				// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
220 221
 				$post = get_queried_object();
221
-				if ( $post )
222
-					$pagename = $post->post_name;
222
+				if ( $post ) {
223
+									$pagename = $post->post_name;
224
+				}
223 225
 			}
224 226
 
225 227
 			$template = get_post_meta('theme-page-template', $id);
226 228
 
227
-			if ( $template != 'index' )
228
-				$templates[] = $template;
229
-			if ( $pagename )
230
-				$templates[] = "page-$pagename";
231
-			if ( $id )
232
-				$templates[] = "page-$id";
229
+			if ( $template != 'index' ) {
230
+							$templates[] = $template;
231
+			}
232
+			if ( $pagename ) {
233
+							$templates[] = "page-$pagename";
234
+			}
235
+			if ( $id ) {
236
+							$templates[] = "page-$id";
237
+			}
233 238
 			$templates[] = '';
234 239
 
235 240
 		// Page
@@ -245,24 +250,30 @@  discard block
 block discarded – undo
245 250
 			if ( ! $pagename && $id ) {
246 251
 				// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
247 252
 				$post = get_queried_object();
248
-				if ( $post )
249
-					$pagename = $post->post_name;
253
+				if ( $post ) {
254
+									$pagename = $post->post_name;
255
+				}
250 256
 			}
251 257
 
252
-			if ( $template != 'index' )
253
-				$templates[] = $template;
254
-			if ( $pagename )
255
-				$templates[] = "page-$pagename";
256
-			if ( $id )
257
-				$templates[] = "page-$id";
258
+			if ( $template != 'index' ) {
259
+							$templates[] = $template;
260
+			}
261
+			if ( $pagename ) {
262
+							$templates[] = "page-$pagename";
263
+			}
264
+			if ( $id ) {
265
+							$templates[] = "page-$id";
266
+			}
258 267
 			$templates[] = 'page';
259 268
 
260 269
 
261 270
 		// Default
262 271
 
263
-		else:
272
+		else {
273
+			:
264 274
 
265 275
 			$templates[] = $type;
276
+		}
266 277
 
267 278
 		endif;
268 279
 
@@ -292,7 +303,9 @@  discard block
 block discarded – undo
292 303
 
293 304
 		preg_match('/classy\-(.*)/', $template_slug, $matches);
294 305
 
295
-		if ( $matches && isset($matches[1]) ) return $matches[1];
306
+		if ( $matches && isset($matches[1]) ) {
307
+			return $matches[1];
308
+		}
296 309
 
297 310
 		return false;
298 311
 
@@ -338,9 +351,11 @@  discard block
 block discarded – undo
338 351
 
339 352
 		elseif ( is_paged() && $template = self::get_available_template('paged') ) :
340 353
 
341
-		else :
354
+		else {
355
+			:
342 356
 		
343 357
 			$template = 'index';
358
+		}
344 359
 
345 360
 		endif;
346 361
 
@@ -361,7 +376,8 @@  discard block
 block discarded – undo
361 376
 
362 377
 			return $template;	
363 378
 
364
-		} else {
379
+		}
380
+		else {
365 381
 
366 382
 			return $template . '.' . $template;
367 383
 			
@@ -414,13 +430,15 @@  discard block
 block discarded – undo
414 430
 
415 431
 				$scope = array_merge($common_scope, $data);
416 432
 
417
-			} else {
433
+			}
434
+			else {
418 435
 
419 436
 				$scope = $common_scope;
420 437
 
421 438
 			}
422 439
 
423
-		} else {
440
+		}
441
+		else {
424 442
 
425 443
 			$current_page = self::get_current_page();
426 444
 
@@ -451,7 +469,9 @@  discard block
 block discarded – undo
451 469
 			
452 470
 			if ( !empty($filename) ) {
453 471
 
454
-				if ( ! preg_match( '/\{\{\-\-\s*Template Name:(.*)\s*\-\-\}\}/mi', file_get_contents( $filename ), $header ) ) continue;
472
+				if ( ! preg_match( '/\{\{\-\-\s*Template Name:(.*)\s*\-\-\}\}/mi', file_get_contents( $filename ), $header ) ) {
473
+					continue;
474
+				}
455 475
 
456 476
 				$template_name = trim($header[1]);
457 477
 
Please login to merge, or discard this patch.