Completed
Push — develop ( 0b0716...7823b4 )
by Paul
02:04
created

Render::field()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
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( ']]>', ']]&gt;', 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 field( $name, array $args = [] )
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
	{
86
	}
87
88
	public function form( $name, array $args = [] )
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
	{
90
	}
91
92
	public function gallery( array $args = [] )
93
	{
94
		echo $this->media->gallery( $args );
95
	}
96
97
	public function title( $metaKey = false, array $attributes = [] )
98
	{
99
		$tag = apply_filters( 'castor/render/title/tag', 'h2' );
100
		$value = $metaKey
101
			? $this->postmeta->get( $metaKey )
102
			: $this->theme->pageTitle();
103
104
		if( !$value )return;
105
106
		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes );
107
	}
108
109
	/**
110
	 * @param array|string $args
111
	 *
112
	 * @return string|null
113
	 */
114
	public function video( $args )
115
	{
116
		echo $this->media->video( $args );
117
	}
118
}
119