1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Html; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Database\DefaultsManager; |
6
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
7
|
|
|
use GeminiLabs\SiteReviews\Helper; |
8
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Field; |
9
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Template; |
10
|
|
|
use GeminiLabs\SiteReviews\Modules\Translator; |
11
|
|
|
|
12
|
|
|
class Settings |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param string $id |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
public function buildFields( $id ) |
19
|
|
|
{ |
20
|
|
|
$method = glsr( Helper::class )->buildMethodName( $id, 'getTemplateContextFor' ); |
21
|
|
|
$context = !method_exists( $this, $method ) |
22
|
|
|
? $this->getTemplateContext( $id ) |
23
|
|
|
: $this->$method( $id ); |
24
|
|
|
return glsr( Template::class )->build( 'pages/settings/'.$id, [ |
25
|
|
|
'context' => $context, |
26
|
|
|
]); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $partialPath |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function render( $partialPath, array $args = [] ) |
34
|
|
|
{ |
35
|
|
|
echo $this->build( $partialPath, $args ); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
protected function getSettingFields( $path ) |
42
|
|
|
{ |
43
|
|
|
$settings = glsr( DefaultsManager::class )->settings(); |
44
|
|
|
return array_filter( $settings, function( $key ) use( $path ) { |
45
|
|
|
return glsr( Helper::class )->startsWith( $path, $key ); |
46
|
|
|
}, ARRAY_FILTER_USE_KEY ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $id |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
protected function getTemplateContext( $id ) |
54
|
|
|
{ |
55
|
|
|
$fields = $this->getSettingFields( $this->normalizeSettingPath( $id )); |
56
|
|
|
$rows = ''; |
57
|
|
|
foreach( $fields as $name => $field ) { |
58
|
|
|
$field = wp_parse_args( $field, [ |
59
|
|
|
'is_setting' => true, |
60
|
|
|
'name' => $name, |
61
|
|
|
]); |
62
|
|
|
$rows.= new Field( $field ); |
63
|
|
|
} |
64
|
|
|
return [ |
65
|
|
|
'rows' => $rows, |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function getTemplateContextForTranslations() |
73
|
|
|
{ |
74
|
|
|
$translations = glsr( Translator::class )->renderAll(); |
75
|
|
|
$class = empty( $translations ) |
76
|
|
|
? 'glsr-hidden' |
77
|
|
|
: ''; |
78
|
|
|
return [ |
79
|
|
|
'class' => $class, |
80
|
|
|
'database_key' => OptionManager::databaseKey(), |
81
|
|
|
'translations' => $translations, |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
protected function normalizeSettingPath( $path ) |
89
|
|
|
{ |
90
|
|
|
return glsr( Helper::class )->prefixString( rtrim( $path, '.' ), 'settings.' ); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.