1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\Castor\Helpers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\Castor\Helpers\Media; |
6
|
|
|
use GeminiLabs\Castor\Helpers\PostMeta; |
7
|
|
|
use GeminiLabs\Castor\Helpers\Theme; |
8
|
|
|
use GeminiLabs\Castor\Helpers\Utility; |
9
|
|
|
|
10
|
|
|
class Render |
11
|
|
|
{ |
12
|
|
|
public $media; |
13
|
|
|
public $postmeta; |
14
|
|
|
public $theme; |
15
|
|
|
public $utility; |
16
|
|
|
|
17
|
|
View Code Duplication |
public function __construct( Media $media, PostMeta $postmeta, Theme $theme, Utility $utility ) |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$this->media = $media; |
20
|
|
|
$this->postmeta = $postmeta; |
21
|
|
|
$this->theme = $theme; |
22
|
|
|
$this->utility = $utility; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function blockquote( $metaKey = false, array $attributes = [] ) |
26
|
|
|
{ |
27
|
|
|
if( $value = $this->postmeta->get( $metaKey )) { |
28
|
|
|
$this->utility->printTag( 'blockquote', wp_strip_all_tags( $value ), $attributes ); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function button( $postId = 0, $title = false ) |
33
|
|
|
{ |
34
|
|
|
$post = get_post( $postId ); |
35
|
|
|
|
36
|
|
|
if( !$postId || !$post )return; |
37
|
|
|
if( !$title ) { |
38
|
|
|
$title = $post->post_title; |
39
|
|
|
} |
40
|
|
|
printf( '<a href="%s" class="button"><span>%s</span></a>', |
41
|
|
|
get_permalink( $post->ID ), |
42
|
|
|
$title |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function buttons( $postIds = [] ) |
47
|
|
|
{ |
48
|
|
|
foreach( (array) $postIds as $postId ) { |
49
|
|
|
$this->button( $postId ); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function content( $metaKey = false ) |
54
|
|
|
{ |
55
|
|
|
$content = $metaKey |
56
|
|
|
? $this->postmeta->get( $metaKey ) |
57
|
|
|
: get_the_content(); |
58
|
|
|
|
59
|
|
|
echo str_replace( ']]>', ']]>', apply_filters( 'the_content', $content )); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function featured( $args = [] ) |
63
|
|
|
{ |
64
|
|
|
$args = wp_parse_args( $args, [ |
65
|
|
|
'class' => 'featured', |
66
|
|
|
'image' => get_post_thumbnail_id(), |
67
|
|
|
'video' => 'featured_video', |
68
|
|
|
]); |
69
|
|
|
$featuredHtml = $this->media->video( wp_parse_args( $args, [ |
70
|
|
|
'url' => $args['video'], |
71
|
|
|
])); |
72
|
|
|
if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] )) { |
73
|
|
|
$featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div><figcaption>%s</figcaption>', |
74
|
|
|
$featuredImage->large['url'], |
75
|
|
|
$featuredImage->alt, |
76
|
|
|
$featuredImage->caption |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
if( !empty( $featuredHtml )) { |
80
|
|
|
printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml ); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function gallery( array $args = [] ) |
85
|
|
|
{ |
86
|
|
|
echo $this->media->gallery( $args ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function title( $metaKey = false, array $attributes = [] ) |
90
|
|
|
{ |
91
|
|
|
$tag = apply_filters( 'castor/render/title/tag', 'h2' ); |
92
|
|
|
$value = $metaKey |
93
|
|
|
? $this->postmeta->get( $metaKey ) |
94
|
|
|
: $this->theme->pageTitle(); |
95
|
|
|
|
96
|
|
|
if( !$value )return; |
97
|
|
|
|
98
|
|
|
$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param array|string $args |
103
|
|
|
* |
104
|
|
|
* @return string|null |
105
|
|
|
*/ |
106
|
|
|
public function video( $args ) |
107
|
|
|
{ |
108
|
|
|
echo $this->media->video( $args ); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.