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
|
|
|
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 copyright( array $args = [] ) |
63
|
|
|
{ |
64
|
|
|
extract( shortcode_atts([ |
|
|
|
|
65
|
|
|
'copyright' => sprintf( '<span>%s </span>©', __( 'Copyright', 'castor' )), |
66
|
|
|
'date' => date( 'Y' ), |
67
|
|
|
'name' => get_bloginfo( 'name' ), |
68
|
|
|
'separator' => '—', |
69
|
|
|
], $args )); |
70
|
|
|
if( $separator ) { |
71
|
|
|
$separator .= ' '; |
72
|
|
|
} |
73
|
|
|
printf( '%s %s %s%s', $copyright, $date, $separator, $name ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function featured( $args = [] ) |
77
|
|
|
{ |
78
|
|
|
$args = wp_parse_args( $args, [ |
79
|
|
|
'class' => 'featured', |
80
|
|
|
'image' => get_post_thumbnail_id(), |
81
|
|
|
'player' => '', |
82
|
|
|
'video' => 'featured_video', |
83
|
|
|
]); |
84
|
|
|
$featuredHtml = $this->media->video( wp_parse_args( $args, [ |
85
|
|
|
'url' => $args['video'], |
86
|
|
|
])); |
87
|
|
|
if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] )) { |
88
|
|
|
$featuredCaption = $featuredImage->caption |
89
|
|
|
? sprintf( '<figcaption>%s</figcaption>', $featuredImage->caption ) |
90
|
|
|
: ''; |
91
|
|
|
$featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div>%s', |
92
|
|
|
$featuredImage->large['url'], |
93
|
|
|
$featuredImage->alt, |
94
|
|
|
$featuredCaption |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
if( !empty( $featuredHtml )) { |
98
|
|
|
printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml ); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function field( $name, array $args = [] ) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function form( $name, array $args = [] ) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function gallery( array $args = [] ) |
111
|
|
|
{ |
112
|
|
|
echo $this->media->gallery( $args ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function madeWithLove( $name ) |
116
|
|
|
{ |
117
|
|
|
printf( __( 'Made with %s by %s', 'castor' ), |
118
|
|
|
file_get_contents( sprintf( '%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets )), |
119
|
|
|
$name |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function title( $metaKey = false, array $attributes = [] ) |
124
|
|
|
{ |
125
|
|
|
$tag = apply_filters( 'castor/render/title/tag', 'h2' ); |
126
|
|
|
$value = $metaKey |
127
|
|
|
? $this->postmeta->get( $metaKey ) |
|
|
|
|
128
|
|
|
: $this->theme->pageTitle(); |
129
|
|
|
|
130
|
|
|
if( !$value )return; |
131
|
|
|
|
132
|
|
|
$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param array|string $args |
137
|
|
|
* |
138
|
|
|
* @return string|null |
139
|
|
|
*/ |
140
|
|
|
public function video( $args ) |
141
|
|
|
{ |
142
|
|
|
echo $this->media->video( $args ); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: