-
Notifications
You must be signed in to change notification settings - Fork 220
/
theme.php
201 lines (161 loc) · 4.79 KB
/
theme.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php if (!defined('FW')) die('Forbidden');
/**
* Theme Component
* Works with framework customizations / theme directory
*/
final class _FW_Component_Theme
{
private static $cache_key = 'fw_theme';
/**
* @var FW_Theme_Manifest
*/
public $manifest;
public function __construct()
{
{
$manifest = array();
@include fw_get_template_customizations_directory('/theme/manifest.php');
$this->manifest = new FW_Theme_Manifest($manifest);
}
}
/**
* @internal
*/
public function _init()
{
add_action('fw_extensions_init', array($this, '_action_fw_extensions_init'));
}
/**
* @internal
*/
public function _after_components_init()
{
}
/**
* Search relative path in: child theme -> parent "theme" directory and return full path
* @param string $rel_path
* @return false|string
*/
public function locate_path($rel_path)
{
if (is_child_theme() && file_exists(fw_get_stylesheet_customizations_directory('/theme'. $rel_path))) {
return fw_get_stylesheet_customizations_directory('/theme'. $rel_path);
}
if (file_exists(fw_get_template_customizations_directory('/theme'. $rel_path))) {
return fw_get_template_customizations_directory('/theme'. $rel_path);
}
return false;
}
/**
* Return array with options from specified name/path
* @param string $name
* @return array
*/
public function get_options($name)
{
$path = $this->locate_path('/options/'. $name .'.php');
if (!$path) {
return array();
}
$variables = fw_get_variables_from_file($path, array('options' => array()));
return $variables['options'];
}
public function get_settings_options()
{
$cache_key = self::$cache_key .'/options/settings';
try {
return FW_Cache::get($cache_key);
} catch (FW_Cache_Not_Found_Exception $e) {
$options = apply_filters('fw_settings_options', $this->get_options('settings'));
FW_Cache::set($cache_key, $options);
return $options;
}
}
public function get_customizer_options()
{
$cache_key = self::$cache_key .'/options/customizer';
try {
return FW_Cache::get($cache_key);
} catch (FW_Cache_Not_Found_Exception $e) {
$options = apply_filters('fw_customizer_options', $this->get_options('customizer'));
FW_Cache::set($cache_key, $options);
return $options;
}
}
public function get_post_options($post_type)
{
$cache_key = self::$cache_key .'/options/posts/'. $post_type;
try {
return FW_Cache::get($cache_key);
} catch (FW_Cache_Not_Found_Exception $e) {
$options = apply_filters('fw_post_options', $this->get_options('posts/'. $post_type), $post_type);
FW_Cache::set($cache_key, $options);
return $options;
}
}
public function get_taxonomy_options($taxonomy)
{
$cache_key = self::$cache_key .'/options/taxonomies/'. $taxonomy;
try {
return FW_Cache::get($cache_key);
} catch (FW_Cache_Not_Found_Exception $e) {
$options = apply_filters('fw_taxonomy_options', $this->get_options('taxonomies/'. $taxonomy),
$taxonomy,
null
);
FW_Cache::set($cache_key, $options);
return $options;
}
}
/**
* Return config key value, or entire config array
* Config array is merged from child configs
* @param string|null $key Multi key format accepted: 'a/b/c'
* @param mixed $default_value
* @return mixed|null
*/
final public function get_config($key = null, $default_value = null)
{
$cache_key = self::$cache_key .'/config';
try {
$config = FW_Cache::get($cache_key);
} catch (FW_Cache_Not_Found_Exception $e) {
$config = array(
/** Toggle Theme Settings form ajax submit */
'settings_form_ajax_submit' => true,
/** Toggle Theme Settings side tabs */
'settings_form_side_tabs' => false,
);
if (file_exists(fw_get_template_customizations_directory('/theme/config.php'))) {
$variables = fw_get_variables_from_file(fw_get_template_customizations_directory('/theme/config.php'), array('cfg' => null));
if (!empty($variables['cfg'])) {
$config = array_merge($config, $variables['cfg']);
unset($variables);
}
}
if (is_child_theme() && file_exists(fw_get_stylesheet_customizations_directory('/theme/config.php'))) {
$variables = fw_get_variables_from_file(fw_get_stylesheet_customizations_directory('/theme/config.php'), array('cfg' => null));
if (!empty($variables['cfg'])) {
$config = array_merge($config, $variables['cfg']);
unset($variables);
}
}
unset($path);
FW_Cache::set($cache_key, $config);
}
return $key === null ? $config : fw_akg($key, $config, $default_value);
}
/**
* @internal
*/
public function _action_fw_extensions_init()
{
if (is_admin() && !fw()->theme->manifest->check_requirements()) {
FW_Flash_Messages::add(
'fw_theme_requirements',
__('Theme requirements not met:', 'fw') .' '. fw()->theme->manifest->get_not_met_requirement_text(),
'warning'
);
}
}
}