|
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 bool |
|
38
|
|
|
*/ |
|
39
|
|
|
public function displaySidebar() |
|
40
|
|
|
{ |
|
41
|
|
|
$conditions = [ |
|
42
|
|
|
is_archive(), |
|
43
|
|
|
is_home(), |
|
44
|
|
|
is_single(), |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
$display = in_array( true, $conditions ); |
|
48
|
|
|
|
|
49
|
|
|
return apply_filters( 'castor/display/sidebar', $display ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $asset |
|
54
|
|
|
* |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function imagePath( $asset ) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->paths( 'dir.stylesheet' ) . 'assets/img/' . $asset; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $asset |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function imageUri( $asset ) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->paths( 'uri.stylesheet' ) . 'assets/img/' . $asset; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function pageTitle() |
|
73
|
|
|
{ |
|
74
|
|
|
foreach( ['is_404', 'is_archive', 'is_home', 'is_page', 'is_search'] as $bool ) { |
|
75
|
|
|
if( !$bool() )continue; |
|
76
|
|
|
$method = sprintf( 'get%sTitle', ucfirst( str_replace( 'is_', '', $bool ))); |
|
77
|
|
|
return $this->$method(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return get_the_title(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param null|string $path |
|
85
|
|
|
* |
|
86
|
|
|
* @return array|string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function paths( $path = null ) |
|
89
|
|
|
{ |
|
90
|
|
|
$paths = [ |
|
91
|
|
|
'dir.stylesheet' => get_stylesheet_directory(), |
|
92
|
|
|
'dir.template' => get_template_directory(), |
|
93
|
|
|
'dir.upload' => wp_upload_dir()['basedir'], |
|
94
|
|
|
'uri.stylesheet' => get_stylesheet_directory_uri(), |
|
95
|
|
|
'uri.template' => get_template_directory_uri(), |
|
96
|
|
|
]; |
|
97
|
|
|
|
|
98
|
|
|
if( is_null( $path )) { |
|
99
|
|
|
return $paths; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return array_key_exists( $path, $paths ) |
|
103
|
|
|
? trailingslashit( $paths[$path] ) |
|
104
|
|
|
: ''; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
protected function get404Title() |
|
108
|
|
|
{ |
|
109
|
|
|
return __( 'Not Found', 'castor' ); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
protected function getArchiveTitle() |
|
113
|
|
|
{ |
|
114
|
|
|
return get_the_archive_title(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
protected function getHomeTitle() |
|
118
|
|
|
{ |
|
119
|
|
|
return ( $home = get_option( 'page_for_posts', true )) |
|
120
|
|
|
? get_the_title( $home ) |
|
121
|
|
|
: __( 'Latest Posts', 'castor' ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
protected function getPageTitle() |
|
125
|
|
|
{ |
|
126
|
|
|
return $title = $this->postmeta->get( 'title' ) |
|
|
|
|
|
|
127
|
|
|
? $title |
|
|
|
|
|
|
128
|
|
|
: get_the_title(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
protected function getSearchTitle() |
|
132
|
|
|
{ |
|
133
|
|
|
return sprintf( __( 'Search Results for %s', 'castor' ), get_search_query() ); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.