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