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