| | |
| | | |
| | | // For valid dashboard pages, check access permissions |
| | | if (!is_404()) { |
| | | $page = $this->getCurrentPage(); |
| | | $page = $this->getCurrentPageSlug(); |
| | | |
| | | // Dashboard home is always accessible (if authenticated) |
| | | if ($page === '' || $page === 'dash') { |
| | |
| | | |
| | | // Check if page exists in allowed pages |
| | | $allowedPages = $this->getUserAllowedPages(); |
| | | if (!in_array($page, $allowedPages)) { |
| | | if (!array_key_exists($page, $allowedPages)) { |
| | | error_log("User not allowed to access page: {$page}"); |
| | | $this->redirectToDashboard(); |
| | | return; |
| | |
| | | public function buildDashboard():void |
| | | { |
| | | $manageableContent = $this->getAllDashboardPages(); |
| | | foreach ($manageableContent as $key => $slug) { |
| | | if ($slug === 'dash') { |
| | | foreach ($manageableContent as $slug => $page) { |
| | | if ($page === 'dash') { |
| | | continue; |
| | | } |
| | | $existing = get_page_by_path($slug, OBJECT, BASE.'dash'); |
| | | if ($existing) { |
| | | continue; |
| | | } |
| | | $title = $this->getTitle($slug); |
| | | $title = $page; |
| | | |
| | | $slug = $this->getSlug($slug, $page); |
| | | |
| | | $ID = wp_insert_post(array( |
| | | 'post_title' => $title, |
| | |
| | | } |
| | | |
| | | // Get current page/section |
| | | $page = $this->getCurrentPage(); |
| | | $page = $this->getCurrentPageTitle(); |
| | | $config = $this->getConfig($page); |
| | | if(!empty($config)) { |
| | | add_filter('jvbLoadingIcon', function() use ($config) { |
| | | return jvbIcon($config['icon']); |
| | | return $config['icon']; |
| | | }); |
| | | } |
| | | $integrationSlugs = array_map(function($name) { |
| | |
| | | wp_enqueue_script('jvb-content'); |
| | | wp_enqueue_script('jvb-crud'); |
| | | |
| | | $page = $this->getCurrentPage(); |
| | | $page = $this->getCurrentPageSlug(); |
| | | |
| | | switch ($page) { |
| | | case 'notifications': |
| | |
| | | do_action('jvbDashScripts', $page); |
| | | } |
| | | |
| | | protected function getCurrentPage():string |
| | | protected function getCurrentPageTitle():string |
| | | { |
| | | if (is_post_type_archive(BASE.'dash')) { |
| | | return 'dash'; |
| | | } |
| | | |
| | | global $post; |
| | | if (!$post) { |
| | | return ''; |
| | | } |
| | | |
| | | return $post->post_title; |
| | | } |
| | | protected function getCurrentPageSlug():string |
| | | { |
| | | if (is_post_type_archive(BASE.'dash')) { |
| | | return 'dash'; |
| | |
| | | |
| | | return $post->post_name; |
| | | } |
| | | protected function getIcon(string $slug, string $page):string |
| | | { |
| | | return $this->cache->remember('icon_'.sanitize_title($page), function() use ($slug, $page) { |
| | | $icon = sanitize_title($page); |
| | | if (!is_numeric($slug)) { |
| | | $config = Features::getConfig($slug); |
| | | if (array_key_exists('icon', $config)) { |
| | | $icon = $config['icon']; |
| | | } |
| | | } |
| | | return $icon; |
| | | }); |
| | | } |
| | | protected function getSlug(string $slug, string $page):string |
| | | { |
| | | return $this->cache->remember('slug_'.sanitize_title($page), function() use ($slug, $page) { |
| | | if (!is_numeric($slug)) { |
| | | return $slug; |
| | | } else { |
| | | return sanitize_title($page); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | protected function renderHeader():void |
| | | { |
| | |
| | | <link rel="preconnect" href="<?= get_home_url()?>"/> |
| | | <?php wp_head(); ?> |
| | | </head> |
| | | <body class="dashboard<?= ' '.$this->getCurrentPage()?>"> |
| | | <body class="dashboard<?= ' '.$this->getCurrentPageSlug()?>"> |
| | | <?php jvbAccessibility();?> |
| | | <header> |
| | | <?php |
| | |
| | | <?= TaxonomySelector::outputSelectorModal() ?> |
| | | <nav class="dashboard-nav"> |
| | | <?php |
| | | $current_page = $this->getCurrentPage(); |
| | | $current_page = $this->getCurrentPageSlug(); |
| | | $pages = $this->getUserAllowedPages()?:[]; |
| | | |
| | | echo '<ul>'; |
| | | foreach ($pages as $page) { |
| | | // Add data-page attribute for the navigator |
| | | $active = ($current_page == $page) ? ' class="current"' : ''; |
| | | $current = ($current_page == $page) ? ' aria-current="page"' : ''; |
| | | $config = $this->getConfig($page); |
| | | $icon = $config['icon']??$page; |
| | | $title = ucwords(str_replace('-', ' ', $page)); |
| | | foreach ($pages as $slug => $page) { |
| | | $slug = $this->getSlug($slug, $page); |
| | | $icon = $this->getIcon($slug, $page); |
| | | // Add data-page attribute for the navigator |
| | | $active = ($current_page == $slug) ? ' class="current"' : ''; |
| | | $current = ($current_page == $slug) ? ' aria-current="page"' : ''; |
| | | |
| | | $link = ($page === 'dash') ? '/'.$page : "/dash/$page"; |
| | | |
| | | $link = ($page === 'dash') ? '/'.$page : "/dash/$slug"; |
| | | printf( |
| | | '<li%s><a href="%s"%s data-page="%s" data-dash title="%s">%s<span>%s</span></a></li>', |
| | | $active, |
| | | get_home_url(null, $link), |
| | | $current, |
| | | $slug, |
| | | $page, |
| | | $title, |
| | | jvbIcon($icon, ['title'=> $title]), |
| | | $title |
| | | jvbIcon($icon, ['title'=> $page]), |
| | | $page |
| | | ); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | <?php |
| | | do_action('jvbRenderDashboardSettings', $this->getCurrentPage()); |
| | | do_action('jvbRenderDashboardSettings', $this->getCurrentPageSlug()); |
| | | ?> |
| | | <?php wp_footer(); ?> |
| | | |
| | |
| | | echo '<p>Welcome back!</p>'; |
| | | |
| | | $pages = $this->getUserAllowedPages(); |
| | | error_log('Pages: '.print_r($pages, true)); |
| | | |
| | | echo '<h2>What would you like to do today?</h2>'; |
| | | |
| | |
| | | $title = $this->getTitle($page); |
| | | |
| | | $description = $this->getDescription($page); |
| | | $icon = $page; |
| | | if (!is_numeric($slug)) { |
| | | $config = Features::getConfig($slug); |
| | | if (array_key_exists('icon', $config)) { |
| | | $icon = $config['icon']; |
| | | } |
| | | } else { |
| | | $slug = sanitize_title($page); |
| | | } |
| | | |
| | | $slug = $this->getSlug($slug, $page); |
| | | $icon = $this->getIcon($slug, $page); |
| | | if ($title !== '') { |
| | | echo '<li><p><a href="'.get_home_url(null, '/dash/'.$slug.'/').'" |
| | | data-page="'.$slug.'" data-dash>'.jvbIcon($icon).ucwords($title).'</a></p></li>'; |
| | |
| | | |
| | | // Add feature-dependent pages (non-config) |
| | | if (Features::forSite()->has('referrals')) { |
| | | $pages[] = 'referrals'; |
| | | $pages[] = 'Referrals'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('can_invite')) { |
| | | $pages[] = 'invites'; |
| | | $pages[] = 'Invites'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('term_approval')) { |
| | | $pages[] = 'approvals'; |
| | | $pages[] = 'Approvals'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('forum')) { |
| | | $pages[] = 'news'; |
| | | $pages[] = 'News'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('member_content')) { |
| | | $pages[] = 'metrics'; |
| | | $pages[] = 'Metrics'; |
| | | } |
| | | |
| | | if (Features::forSite()->has('favourites')) { |
| | | $pages[] = 'favourites'; |
| | | $pages[] = 'Favourites'; |
| | | } |
| | | |
| | | if (Features::anyContentHas('karma') || Features::anyTaxonomyHas('karma') || Features::anyUserHas('karma')) { |
| | | $pages[] = 'karmic-score'; |
| | | $pages[] = 'Karmic Score'; |
| | | } |
| | | |
| | | if (Features::forSite()->has('notifications')) { |
| | | $pages[] = 'notifications'; |
| | | $pages[] = 'Notifications'; |
| | | } |
| | | |
| | | if (Features::forSite()->has('support')) { |
| | | $pages[] = 'support'; |
| | | $pages[] = 'Support'; |
| | | } |
| | | |
| | | if (Features::hasAnyIntegration()) { |
| | | $pages[] = 'integrations'; |
| | | $pages[] = 'Integrations'; |
| | | } |
| | | |
| | | // Add all content types (with config keys) |
| | | foreach (JVB_CONTENT as $slug => $config) { |
| | | $pages[$slug] = sanitize_title($config['plural']); |
| | | $pages[$slug] = $config['plural']; |
| | | } |
| | | |
| | | foreach (JVB_TAXONOMY as $slug=>$config) { |
| | | $pages[$slug] = sanitize_title($config['plural']); |
| | | $pages[$slug] = $config['plural']; |
| | | } |
| | | |
| | | // Allow filtering |