Completed
Push — develop ( 4e701f...f04956 )
by Paul
02:17
created

Theme::copyright()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\Castor\Helpers;
4
5
use GeminiLabs\Castor\Helpers\PostMeta;
6
7
class Theme
8
{
9
	public $postmeta;
10
11
	public function __construct( PostMeta $postmeta )
12
	{
13
		$this->postmeta = $postmeta;
14
	}
15
16
	/**
17
	 * @param string $asset
18
	 *
19
	 * @return string
20
	 */
21
	public function assetPath( $asset )
22
	{
23
		return $this->paths( 'dir.stylesheet' ) . 'assets/' . $asset;
24
	}
25
26
	/**
27
	 * @param string $asset
28
	 *
29
	 * @return string
30
	 */
31
	public function assetUri( $asset )
32
	{
33
		return $this->paths( 'uri.stylesheet' ) . 'assets/' . $asset;
34
	}
35
36
	/**
37
	 * @return string
38
	 */
39
	public function copyright()
40
	{
41
		return __( 'Copyright', 'castor' ) . ' &copy; ' . date( 'Y' ) . ', ' . get_bloginfo( 'name' );
42
	}
43
44
	/**
45
	 * @return bool
46
	 */
47
	public function displaySidebar()
48
	{
49
		$conditions = [
50
			is_archive(),
51
			is_home(),
52
			is_single(),
53
		];
54
55
		$display = in_array( true, $conditions );
56
57
		return apply_filters( 'castor/display/sidebar', $display );
58
	}
59
60
	/**
61
	 * @param string $asset
62
	 *
63
	 * @return string
64
	 */
65
	public function imagePath( $asset )
66
	{
67
		return $this->paths( 'dir.stylesheet' ) . 'assets/img/' . $asset;
68
	}
69
70
	/**
71
	 * @param string $asset
72
	 *
73
	 * @return string
74
	 */
75
	public function imageUri( $asset )
76
	{
77
		return $this->paths( 'uri.stylesheet' ) . 'assets/img/' . $asset;
78
	}
79
80
	public function pageTitle()
81
	{
82
		foreach( ['is_404', 'is_archive', 'is_home', 'is_page', 'is_search'] as $bool ) {
83
			if( !$bool() )continue;
84
			$method = sprintf( 'get%sTitle', ucfirst( str_replace( 'is_', '', $bool )));
85
			return $this->$method();
86
		}
87
88
		return get_the_title();
89
	}
90
91
	/**
92
	 * @param null|string $path
93
	 *
94
	 * @return array|string
95
	 */
96
	public function paths( $path = null )
97
	{
98
		$paths = [
99
			'dir.stylesheet' => get_stylesheet_directory(),
100
			'dir.template'   => get_template_directory(),
101
			'dir.upload'     => wp_upload_dir()['basedir'],
102
			'uri.stylesheet' => get_stylesheet_directory_uri(),
103
			'uri.template'   => get_template_directory_uri(),
104
		];
105
106
		if( is_null( $path )) {
107
			return $paths;
108
		}
109
110
		return array_key_exists( $path, $paths )
111
			? trailingslashit( $paths[$path] )
112
			: '';
113
	}
114
115
	/**
116
	 * @param null|string $path
117
	 *
118
	 * @return string|null
119
	 */
120
	public function svg( $path = null )
121
	{
122
		if( $svg = file_get_contents( $this->imageUri( $path ))) {
123
			return $svg;
124
		}
125
	}
126
127
	protected function get404Title()
128
	{
129
		return __( 'Not Found', 'castor' );
130
	}
131
132
	protected function getArchiveTitle()
133
	{
134
		return get_the_archive_title();
135
	}
136
137
	protected function getHomeTitle()
138
	{
139
		return ( $home = get_option( 'page_for_posts', true ))
140
			? get_the_title( $home )
141
			: __( 'Latest Posts', 'castor' );
142
	}
143
144
	protected function getPageTitle()
145
	{
146
		return ($title = $this->postmeta->get( 'title' ))
147
			? $title
148
			: get_the_title();
149
	}
150
151
	protected function getSearchTitle()
152
	{
153
		return sprintf( __( 'Search Results for %s', 'castor' ), get_search_query() );
154
	}
155
}
156