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
|
|
|
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
|
|
View Code Duplication |
public function blockquote( $metaKey = false, array $attributes = [] ) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$tag = 'blockquote'; |
28
|
|
|
$value = $this->postmeta->get( $metaKey ); |
29
|
|
|
|
30
|
|
|
if( !$value )return; |
31
|
|
|
|
32
|
|
|
$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function button( $postId = 0, $title = false ) |
36
|
|
|
{ |
37
|
|
|
$post = get_post( $postId ); |
38
|
|
|
|
39
|
|
|
if( !$post )return; |
40
|
|
|
if( !$title ) { |
41
|
|
|
$title = $post->post_title; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
printf( '<a href="%s" class="button"><span>%s</span></a>', |
45
|
|
|
get_permalink( $post->ID ), |
46
|
|
|
$title |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function buttons( array $postIds = [] ) |
51
|
|
|
{ |
52
|
|
|
foreach( $postIds as $postId ) { |
53
|
|
|
$this->button( $postId ); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function content( $metaKey = false ) |
58
|
|
|
{ |
59
|
|
|
$content = $metaKey |
60
|
|
|
? $this->postmeta->get( $metaKey ) |
61
|
|
|
: get_the_content(); |
62
|
|
|
|
63
|
|
|
$content = apply_filters( 'the_content', $content ); |
64
|
|
|
|
65
|
|
|
print str_replace( ']]>', ']]>', $content ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function gallery( array $args = [] ) |
69
|
|
|
{ |
70
|
|
|
print $this->media->gallery( $args ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
public function title( $metaKey = false, array $attributes = [] ) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$tag = apply_filters( 'castor/render/title/tag', 'h2' ); |
76
|
|
|
$value = $metaKey |
77
|
|
|
? $this->postmeta->get( $metaKey ) |
78
|
|
|
: $this->theme->pageTitle(); |
79
|
|
|
|
80
|
|
|
if( !$value )return; |
81
|
|
|
|
82
|
|
|
$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function video( $metaKey = 'video', $screenshotMetaKey = false ) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.