1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\Castor\Helpers; |
4
|
|
|
|
5
|
|
|
class Render |
6
|
|
|
{ |
7
|
|
|
public $media; |
8
|
|
|
public $postmeta; |
9
|
|
|
public $theme; |
10
|
|
|
public $utility; |
11
|
|
|
|
12
|
|
|
public function __construct(Media $media, PostMeta $postmeta, Theme $theme, Utility $utility) |
13
|
|
|
{ |
14
|
|
|
$this->media = $media; |
15
|
|
|
$this->postmeta = $postmeta; |
16
|
|
|
$this->theme = $theme; |
17
|
|
|
$this->utility = $utility; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function blockquote($metaKey = false, array $attributes = []) |
21
|
|
|
{ |
22
|
|
|
if ($value = $this->postmeta->get($metaKey)) { |
23
|
|
|
$this->utility->printTag('blockquote', wp_strip_all_tags($value), $attributes); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function button($postId = 0, $title = false, $passthrough = false) |
28
|
|
|
{ |
29
|
|
|
if ($passthrough) { |
30
|
|
|
$url = $postId; |
31
|
|
|
} |
32
|
|
|
if (!isset($url)) { |
33
|
|
|
$url = get_permalink($postId); |
34
|
|
|
if (!$title) { |
35
|
|
|
$title = get_the_title($postId); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
if (!$title || !$url) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
printf('<a href="%s" class="button"><span>%s</span></a>', $url, $title); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function buttons($postIds = []) |
45
|
|
|
{ |
46
|
|
|
foreach ((array) $postIds as $postId) { |
47
|
|
|
$this->button($postId); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function content($metaKey = false, $passthrough = false) |
52
|
|
|
{ |
53
|
|
|
if ($passthrough) { |
54
|
|
|
$content = $metaKey; |
55
|
|
|
} |
56
|
|
|
if (!isset($content)) { |
57
|
|
|
$content = $metaKey |
58
|
|
|
? $this->postmeta->get($metaKey) |
59
|
|
|
: get_the_content(); |
60
|
|
|
} |
61
|
|
|
echo str_replace(']]>', ']]>', apply_filters('the_content', $content)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function copyright(array $args = []) |
65
|
|
|
{ |
66
|
|
|
$args = shortcode_atts([ |
67
|
|
|
'copyright' => sprintf('<span>%s </span>©', __('Copyright', 'castor')), |
68
|
|
|
'date' => date('Y'), |
69
|
|
|
'name' => get_bloginfo('name'), |
70
|
|
|
'separator' => '—', |
71
|
|
|
], $args); |
72
|
|
|
extract($args); |
73
|
|
|
if ($separator) { |
74
|
|
|
$separator .= ' '; |
75
|
|
|
} |
76
|
|
|
printf('%s %s %s%s', $copyright, $date, $separator, $name); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function featured($args = []) |
80
|
|
|
{ |
81
|
|
|
$args = wp_parse_args($args, [ |
82
|
|
|
'class' => 'featured', |
83
|
|
|
'image' => get_post_thumbnail_id(), |
84
|
|
|
'player' => '', |
85
|
|
|
'video' => 'featured_video', |
86
|
|
|
]); |
87
|
|
|
$featuredHtml = $this->media->video(wp_parse_args($args, [ |
88
|
|
|
'url' => $args['video'], |
89
|
|
|
])); |
90
|
|
|
if (empty($featuredHtml) && $featuredImage = $this->media->getImage($args['image'])) { |
91
|
|
|
$featuredCaption = $featuredImage->caption |
92
|
|
|
? sprintf('<figcaption>%s</figcaption>', $featuredImage->caption) |
93
|
|
|
: ''; |
94
|
|
|
$featuredHtml = sprintf('<div class="featured-image"><img src="%s" alt="%s"></div>%s', |
95
|
|
|
$featuredImage->large['url'], |
96
|
|
|
$featuredImage->alt, |
97
|
|
|
$featuredCaption |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
if (!empty($featuredHtml)) { |
101
|
|
|
printf('<figure class="%s">%s</figure>', $args['class'], $featuredHtml); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function field($name, array $args = []) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function form($name, array $args = []) |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function gallery(array $args = []) |
114
|
|
|
{ |
115
|
|
|
echo $this->media->gallery($args); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function h1($string, array $attributes = []) |
119
|
|
|
{ |
120
|
|
|
$this->utility->printTag('h1', wp_strip_all_tags($string), $attributes); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function h2($string, array $attributes = []) |
124
|
|
|
{ |
125
|
|
|
$this->utility->printTag('h2', wp_strip_all_tags($string), $attributes); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function h3($string, array $attributes = []) |
129
|
|
|
{ |
130
|
|
|
$this->utility->printTag('h3', wp_strip_all_tags($string), $attributes); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function h4($string, array $attributes = []) |
134
|
|
|
{ |
135
|
|
|
$this->utility->printTag('h4', wp_strip_all_tags($string), $attributes); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function h5($string, array $attributes = []) |
139
|
|
|
{ |
140
|
|
|
$this->utility->printTag('h5', wp_strip_all_tags($string), $attributes); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function h6($string, array $attributes = []) |
144
|
|
|
{ |
145
|
|
|
$this->utility->printTag('h6', wp_strip_all_tags($string), $attributes); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function madeWithLove($name) |
149
|
|
|
{ |
150
|
|
|
printf(__('Made with %s by %s', 'castor'), |
151
|
|
|
file_get_contents(sprintf('%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets)), |
152
|
|
|
$name |
153
|
|
|
); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function p($string, array $attributes = []) |
157
|
|
|
{ |
158
|
|
|
$this->utility->printTag('p', wp_strip_all_tags($string), $attributes); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function title($metaKey = false, array $attributes = []) |
162
|
|
|
{ |
163
|
|
|
$tag = apply_filters('castor/render/title/tag', 'h2'); |
164
|
|
|
$value = $metaKey |
165
|
|
|
? $this->postmeta->get($metaKey) |
166
|
|
|
: $this->theme->pageTitle(); |
167
|
|
|
|
168
|
|
|
if (!$value) { |
169
|
|
|
return; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$this->utility->printTag($tag, wp_strip_all_tags($value), $attributes); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param array|string $args |
177
|
|
|
* |
178
|
|
|
* @return string|null |
179
|
|
|
*/ |
180
|
|
|
public function video($args) |
181
|
|
|
{ |
182
|
|
|
echo $this->media->video($args); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.