1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
6
|
|
|
use GeminiLabs\SiteReviews\Controllers\Controller; |
7
|
|
|
use GeminiLabs\SiteReviews\Helper; |
8
|
|
|
use GeminiLabs\SiteReviews\Modules\Console; |
9
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
10
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Settings; |
11
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Template; |
12
|
|
|
use GeminiLabs\SiteReviews\Modules\Notice; |
13
|
|
|
use GeminiLabs\SiteReviews\Modules\System; |
14
|
|
|
|
15
|
|
|
class MenuController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @return void |
19
|
|
|
* @action admin_menu |
20
|
|
|
*/ |
21
|
|
|
public function registerMenuCount() |
22
|
|
|
{ |
23
|
|
|
global $menu, $typenow; |
24
|
|
|
foreach( $menu as $key => $value ) { |
25
|
|
|
if( !isset( $value[2] ) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE )continue; |
26
|
|
|
$postCount = wp_count_posts( Application::POST_TYPE ); |
27
|
|
|
$pendingCount = glsr( Builder::class )->span( number_format_i18n( $postCount->pending ), [ |
28
|
|
|
'class' => 'pending-count', |
29
|
|
|
]); |
30
|
|
|
$awaitingModeration = glsr( Builder::class )->span( $pendingCount, [ |
31
|
|
|
'class' => 'awaiting-mod count-'.$postCount->pending, |
32
|
|
|
]); |
33
|
|
|
$menu[$key][0] .= ' '.$awaitingModeration; |
34
|
|
|
if( $typenow === Application::POST_TYPE ) { |
35
|
|
|
$menu[$key][4].= ' current'; |
36
|
|
|
} |
37
|
|
|
break; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return void |
43
|
|
|
* @action admin_menu |
44
|
|
|
*/ |
45
|
|
|
public function registerSubMenus() |
46
|
|
|
{ |
47
|
|
|
$pages = $this->parseWithFilter( 'submenu/pages', [ |
48
|
|
|
'settings' => __( 'Settings', 'site-reviews' ), |
49
|
|
|
'tools' => __( 'Tools', 'site-reviews' ), |
50
|
|
|
'addons' => __( 'Addons', 'site-reviews' ), |
51
|
|
|
'documentation' => __( 'Documentation', 'site-reviews' ), |
52
|
|
|
]); |
53
|
|
|
foreach( $pages as $slug => $title ) { |
54
|
|
|
$method = glsr( Helper::class )->buildMethodName( 'render-'.$slug.'-menu' ); |
55
|
|
|
$callback = apply_filters( 'site-reviews/addon/submenu/callback', [$this, $method], $slug ); |
56
|
|
|
if( !is_callable( $callback ))continue; |
57
|
|
|
add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, $title, $title, Application::CAPABILITY, $slug, $callback ); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return void |
63
|
|
|
* @see $this->registerSubMenus() |
64
|
|
|
* @callback add_submenu_page |
65
|
|
|
*/ |
66
|
|
|
public function renderAddonsMenu() |
67
|
|
|
{ |
68
|
|
|
$this->renderPage( 'addons', [ |
69
|
|
|
'template' => glsr( Template::class ), |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return void |
75
|
|
|
* @see $this->registerSubMenus() |
76
|
|
|
* @callback add_submenu_page |
77
|
|
|
*/ |
78
|
|
|
public function renderDocumentationMenu() |
79
|
|
|
{ |
80
|
|
|
$tabs = $this->parseWithFilter( 'documentation/tabs', [ |
81
|
|
|
'support' => __( 'Support', 'site-reviews' ), |
82
|
|
|
'faq' => __( 'FAQ', 'site-reviews' ), |
83
|
|
|
'shortcodes' => __( 'Shortcodes', 'site-reviews' ), |
84
|
|
|
'hooks' => __( 'Hooks', 'site-reviews' ), |
85
|
|
|
'functions' => __( 'Functions', 'site-reviews' ), |
86
|
|
|
]); |
87
|
|
|
$this->renderPage( 'documentation', [ |
88
|
|
|
'tabs' => $tabs, |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return void |
94
|
|
|
* @see $this->registerSubMenus() |
95
|
|
|
* @callback add_submenu_page |
96
|
|
|
*/ |
97
|
|
|
public function renderSettingsMenu() |
98
|
|
|
{ |
99
|
|
|
$tabs = $this->parseWithFilter( 'settings/tabs', [ |
100
|
|
|
'general' => __( 'General', 'site-reviews' ), |
101
|
|
|
'reviews' => __( 'Reviews', 'site-reviews' ), |
102
|
|
|
'submissions' => __( 'Submissions', 'site-reviews' ), |
103
|
|
|
'schema' => __( 'Schema', 'site-reviews' ), |
104
|
|
|
'translations' => __( 'Translations', 'site-reviews' ), |
105
|
|
|
'addons' => __( 'Addons', 'site-reviews' ), |
106
|
|
|
'licenses' => __( 'Licenses', 'site-reviews' ), |
107
|
|
|
]); |
108
|
|
|
if( empty( glsr( Helper::class )->getPathValue( 'settings.addons', glsr()->defaults ))) { |
109
|
|
|
unset( $tabs['addons'] ); |
110
|
|
|
} |
111
|
|
|
if( empty( glsr( Helper::class )->getPathValue( 'settings.licenses', glsr()->defaults ))) { |
112
|
|
|
unset( $tabs['licenses'] ); |
113
|
|
|
} |
114
|
|
|
$this->renderPage( 'settings', [ |
115
|
|
|
'notices' => $this->getNotices(), |
116
|
|
|
'settings' => glsr( Settings::class ), |
117
|
|
|
'tabs' => $tabs, |
118
|
|
|
]); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return void |
123
|
|
|
* @see $this->registerSubMenus() |
124
|
|
|
* @callback add_submenu_page |
125
|
|
|
*/ |
126
|
|
|
public function renderToolsMenu() |
127
|
|
|
{ |
128
|
|
|
$tabs = $this->parseWithFilter( 'tools/tabs', [ |
129
|
|
|
'general' => __( 'General', 'site-reviews' ), |
130
|
|
|
'sync' => __( 'Sync Reviews', 'site-reviews' ), |
131
|
|
|
'console' => __( 'Console', 'site-reviews' ), |
132
|
|
|
'system-info' => __( 'System Info', 'site-reviews' ), |
133
|
|
|
]); |
134
|
|
|
if( !apply_filters( 'site-reviews/addon/sync/enable', false )) { |
135
|
|
|
unset( $tabs['sync'] ); |
136
|
|
|
} |
137
|
|
|
$this->renderPage( 'tools', [ |
138
|
|
|
'data' => [ |
139
|
|
|
'context' => [ |
140
|
|
|
'console' => strval( glsr( Console::class )), |
141
|
|
|
'id' => Application::ID, |
142
|
|
|
'system' => strval( glsr( System::class )), |
143
|
|
|
], |
144
|
|
|
'sites' => apply_filters( 'site-reviews/addon/sync/sites', [] ), |
145
|
|
|
], |
146
|
|
|
'notices' => $this->getNotices(), |
147
|
|
|
'tabs' => $tabs, |
148
|
|
|
'template' => glsr( Template::class ), |
149
|
|
|
]); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return void |
154
|
|
|
* @action admin_init |
155
|
|
|
*/ |
156
|
1 |
|
public function setCustomPermissions() |
157
|
|
|
{ |
158
|
1 |
|
foreach( wp_roles()->roles as $role => $value ) { |
159
|
1 |
|
wp_roles()->remove_cap( $role, 'create_'.Application::POST_TYPE ); |
160
|
|
|
} |
161
|
1 |
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
protected function getNotices() |
167
|
|
|
{ |
168
|
|
|
return glsr( Builder::class )->div( glsr( Notice::class )->get(), [ |
169
|
|
|
'id' => 'glsr-notices', |
170
|
|
|
]); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param string $hookSuffix |
175
|
|
|
* @return array |
176
|
|
|
*/ |
177
|
|
|
protected function parseWithFilter( $hookSuffix, array $args = [] ) |
178
|
|
|
{ |
179
|
|
|
return apply_filters( 'site-reviews/addon/'.$hookSuffix, $args ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param string $page |
184
|
|
|
* @return void |
185
|
|
|
*/ |
186
|
|
|
protected function renderPage( $page, array $data = [] ) |
187
|
|
|
{ |
188
|
|
|
$data['http_referer'] = (string)wp_get_referer(); |
189
|
|
|
glsr()->render( 'pages/'.$page.'/index', $data ); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|