| | |
| | | namespace JVBase\managers; |
| | | |
| | | use JVBase\forms\TaxonomySelector; |
| | | use JVBase\managers\CRUD; |
| | | use JVBase\base\Site; |
| | | use JVBase\meta\Form; |
| | | use JVBase\meta\Meta; |
| | | use JVBase\registrar\Registrar;use JVBase\utility\Features; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\ui\Navigation; |
| | | use WP_User; |
| | | |
| | |
| | | $this->cache->flush(); |
| | | $this->user = wp_get_current_user(); |
| | | $this->role = jvbUserRole($this->user->ID); |
| | | $this->userLink = (int)get_user_meta($this->user->ID, BASE.'link', true); |
| | | $this->userLink = (int)get_user_meta($this->user->ID, BASE.'profile_link', true); |
| | | $this->baseURL = get_home_url(null, '/dash'); |
| | | |
| | | add_action('template_redirect', [$this, 'handleRedirects']); |
| | |
| | | // if ($page === 'integrations' || in_array($page, $integrationSlugs)) { |
| | | // // Check integration access |
| | | // if ($page === 'integrations') { |
| | | // if (!Features::hasAnyIntegration('user', $this->role)) { |
| | | // if (!Site::hasAnyIntegration('user', $this->role)) { |
| | | // $this->redirectToDashboard(); |
| | | // } |
| | | // } else { |
| | | // if (!Features::hasIntegration($page, 'user', $this->role)) { |
| | | // if (!Site::hasIntegration($page, 'user', $this->role)) { |
| | | // $this->redirectToDashboard(); |
| | | // } |
| | | // } |
| | |
| | | |
| | | switch ($page) { |
| | | case 'notifications': |
| | | if (Features::forSite()->has('notifications')) { |
| | | if (Site::has('notifications')) { |
| | | wp_enqueue_script('jvb-notification-manager'); |
| | | } |
| | | break; |
| | |
| | | wp_enqueue_script('jvb-crud'); |
| | | break; |
| | | } |
| | | if (Features::forSite()->has('favourites')) { |
| | | if (Site::has('favourites')) { |
| | | wp_enqueue_script('jvb-favourites'); |
| | | wp_localize_script('jvb-favourites-manager', 'favouritesSettings', [ |
| | | 'strings' => [ |
| | |
| | | |
| | | wp_enqueue_script('jvb-creator'); |
| | | |
| | | if (Features::forSite()->has('forum')) { |
| | | if (Site::has('forum')) { |
| | | wp_enqueue_script('jvb-news'); |
| | | } |
| | | do_action('jvbDashScripts', $page); |
| | |
| | | <!DOCTYPE html> |
| | | <html <?php language_attributes(); ?>> |
| | | <head> |
| | | <title><?= (array_key_exists('dashboard_title', JVB_SITE)) ? JVB_SITE['dashboard_title'] : 'Dashboard | '.get_bloginfo('name') ?></title> |
| | | <title><?= Site::dashboardTitle()??'Dashboard | '.get_bloginfo('name') ?></title> |
| | | <meta charset="<?php bloginfo('charset'); ?>"> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| | | <?php |
| | |
| | | |
| | | //Content |
| | | //content types |
| | | //Taxonomies |
| | | $availableContent = array_filter($pages, function($page, $key) { |
| | | return !is_numeric($key) && array_key_exists($key, Registrar::getRegistered('post')); |
| | | $all = array_merge( |
| | | Registrar::getRegistered('post'), |
| | | Registrar::getFeatured('is_content', 'term') |
| | | ); |
| | | $availableContent = array_filter($pages, function($page, $key) use($all) { |
| | | return !is_numeric($key) && in_array($key, $all) && JVB()->roles()->checkRole($this->user, $key); |
| | | }, ARRAY_FILTER_USE_BOTH); |
| | | if (!empty ($availableContent)){ |
| | | $content = $menu->addItem('Your Content', jvbDashIcon('book-bookmark')) |
| | |
| | | $item = $content->addItem($page, $registrar->getIcon()) |
| | | ->url($this->baseURL.'/'.$slug); |
| | | |
| | | $taxonomies = $registrar->registrar->taxonomies; |
| | | if (!empty ($taxonomies)) { |
| | | //TODO: If we add a dedicated 'create item' page, remove this from the empty check |
| | | $itemMenu = $item->submenu($slug); |
| | | foreach ($taxonomies as $s) { |
| | | $taxRegistrar = Registrar::getInstance($s); |
| | | $itemMenu->addItem($taxRegistrar->getPlural(), $taxRegistrar->getIcon()) |
| | | ->url($this->baseURL.'/'.$s); |
| | | if ($registrar->getType() === 'post') { |
| | | $taxonomies = $registrar->registrar->taxonomies; |
| | | if (!empty ($taxonomies)) { |
| | | //TODO: If we add a dedicated 'create item' page, remove this from the empty check |
| | | $itemMenu = $item->submenu($slug); |
| | | foreach ($taxonomies as $s) { |
| | | $taxRegistrar = Registrar::getInstance($s); |
| | | $itemMenu->addItem($taxRegistrar->getPlural(), $taxRegistrar->getIcon()) |
| | | ->url($this->baseURL.'/'.$s); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | //Taxonomies |
| | | |
| | | //Settings |
| | | $settings = $menu->addItem('Settings', jvbDashIcon('faders')) |
| | | ->submenu('settings') |
| | |
| | | return $content; |
| | | } |
| | | |
| | | if (Features::forSite()->has('referrals')) { |
| | | if (Site::has('referrals')) { |
| | | $whatever = JVB()->referrals()->getReferralWelcomeMessage($this->user->ID); |
| | | if (!empty($whatever)) { |
| | | return $whatever; |
| | |
| | | $connection = (array_key_exists($page, $map)) ? $map[$page] : $page; |
| | | if ($connection !== 'integrations') { |
| | | |
| | | $userID = (Features::forSite()->has('has_membership')) ? $this->user->ID : null; |
| | | $userID = (Site::has('has_membership')) ? $this->user->ID : null; |
| | | $integration = JVB()->connect($connection, $userID); |
| | | |
| | | echo '<h1>Managing '.$integration->title.'</h1>'; |
| | |
| | | $pages = []; |
| | | $pages[] = 'SEO'; |
| | | // Add feature-dependent pages (non-config) |
| | | if (Features::forSite()->has('referrals')) { |
| | | if (Site::has('referrals')) { |
| | | $pages[] = 'Referrals'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('can_invite')) { |
| | | $membership = Site::membership(); |
| | | if ($membership && $membership->has('can_invite')) { |
| | | $pages[] = 'Invites'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('term_approval')) { |
| | | if ($membership && $membership->has('term_approval')) { |
| | | $pages[] = 'Approvals'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('forum')) { |
| | | if ($membership && $membership->has('forum')) { |
| | | $pages[] = 'News'; |
| | | } |
| | | |
| | | if (Features::forMembership()->has('member_content')) { |
| | | if ($membership && $membership->has('member_content')) { |
| | | $pages[] = 'Metrics'; |
| | | } |
| | | |
| | | if (Features::forSite()->has('favourites')) { |
| | | if (Site::has('favourites')) { |
| | | $pages[] = 'Favourites'; |
| | | } |
| | | |
| | |
| | | $pages[] = 'Karmic Score'; |
| | | } |
| | | |
| | | if (Features::forSite()->has('notifications')) { |
| | | if (Site::has('notifications')) { |
| | | $pages[] = 'Notifications'; |
| | | } |
| | | |
| | | if (Features::forSite()->has('support')) { |
| | | if (Site::has('support')) { |
| | | $pages[] = 'Support'; |
| | | } |
| | | |
| | | if (Features::hasAnyIntegration()) { |
| | | if (Site::hasAnyIntegration()) { |
| | | $pages[] = 'Integrations'; |
| | | } |
| | | |
| | |
| | | return $pages; |
| | | } |
| | | |
| | | /** |
| | | * Get pages available to a specific role |
| | | * @param string $role The role slug (with or without BASE prefix) |
| | | * @return array |
| | | */ |
| | | protected function getRolePages(string $role):array |
| | | { |
| | | $role = jvbNoBase($role); |
| | | |
| | | if (!Registrar::getInstance($role)){ |
| | | return []; |
| | | } |
| | | |
| | | return Features::forUser($role)->getDashboardPages(); |
| | | } |
| | | |
| | | /** |
| | | * Get pages that a specific user is allowed to access |
| | |
| | | switch ($slug) { |
| | | case 'Integrations': |
| | | foreach($roles as $role) { |
| | | if (Features::hasAnyIntegration('user', $role)) { |
| | | if (Registrar::getInstance($role)->hasAnyIntegrations()) { |
| | | $remove = false; |
| | | } |
| | | } |
| | |
| | | break; |
| | | case 'Approvals': |
| | | $canApprove = false; |
| | | if (Features::forMembership()->has('term_approval')) { |
| | | if ($membership && $membership->has('term_approval')) { |
| | | if (array_key_exists('can_approve', JVB_MEMBERSHIP)) { |
| | | foreach ($roles as $role) { |
| | | if (in_array($role, JVB_MEMBERSHIP['can_approve'])) { |
| | |
| | | break; |
| | | case 'metrics': |
| | | foreach ($roles as $role) { |
| | | if (!empty(Features::forUser($role)->getCreatableContent())) { |
| | | if (!empty(Registrar::getInstance($role)?->getCreatable())) { |
| | | $remove = false; |
| | | } |
| | | } |
| | | break; |
| | | case 'karmic-score': |
| | | foreach ($roles as $role) { |
| | | $contents = Features::forUser($role)->getCreatableContent(); |
| | | $contents = Registrar::getInstance($role)?->getCreatable(); |
| | | if (!empty($contents)) { |
| | | $hasKarma = Registrar::getFeatured('karma'); |
| | | $remove = empty(array_intersect($contents, $hasKarma)); |
| | |
| | | |
| | | $creatable = []; |
| | | foreach ($roles as $role) { |
| | | $roleCreatable = Features::forUser($role)->getCreatableContent(); |
| | | $roleCreatable = Registrar::getInstance($role)?->getCreatable(); |
| | | $creatable = array_merge($creatable, $roleCreatable); |
| | | } |
| | | |