| | |
| | | |
| | | use JetBrains\PhpStorm\NoReturn;use JVBase\forms\TaxonomySelector; |
| | | use JVBase\base\Site; |
| | | use JVBase\meta\Form; |
| | | use JVBase\integrations\ServiceMap;use JVBase\meta\Form; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\ui\Navigation; |
| | | use WP_Error;use WP_Query;use WP_User; |
| | |
| | | */ |
| | | class DashboardManager |
| | | { |
| | | use ServiceMap; |
| | | |
| | | protected WP_User $user; |
| | | protected Cache $cache; |
| | | protected string $role; |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->connect('user')->user(); |
| | | if (JVB_TESTING) { |
| | | $this->cache->flush(); |
| | | } |
| | | $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->user(); |
| | | |
| | | |
| | | add_action('init', [$this, 'registerDashboard']); |
| | | |
| | |
| | | } |
| | | |
| | | public function excludeDashboard(array $IDs):array { |
| | | $this->cache->flush(); |
| | | $exclude = $this->cache->remember( |
| | | 'dashboardIDs', |
| | | function() { |
| | |
| | | */ |
| | | protected function buildIntegrationPages(int $parentID):void |
| | | { |
| | | $integrations = JVB()->getAvailableServices(false); |
| | | |
| | | foreach ($integrations as $name => $integration) { |
| | | $integrations = $this->getAvailableServices(); |
| | | foreach ($integrations as $service) { |
| | | $integration = $this->getService($service); |
| | | $title = $integration->getTitle(); |
| | | |
| | | $slug = sanitize_title($title); |
| | | $this->createDashboardPage($slug, $title, $parentID); |
| | | } |
| | |
| | | } |
| | | $integrationSlugs = array_map(function($name) { |
| | | return sanitize_title(str_replace('_', '-', $name)); |
| | | }, array_keys(JVB()->getAvailableServices(false))); |
| | | }, array_keys($this->getAvailableServices())); |
| | | |
| | | // Check if this is an integration subpage |
| | | if (in_array($page, $integrationSlugs)) { |
| | |
| | | Registrar::withFeature('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); |
| | | return !is_numeric($key) && in_array($key, $all) && Roles::getInstance()()->checkRole($this->user, $key); |
| | | }, ARRAY_FILTER_USE_BOTH); |
| | | if (!empty ($availableContent)){ |
| | | $content = $menu->addItem('Your Content', jvbDashIcon('book-bookmark')) |
| | |
| | | } |
| | | |
| | | if (Site::has('referrals')) { |
| | | $whatever = JVB()->referrals()->getReferralWelcomeMessage($this->user->ID); |
| | | $whatever = Referrals::getInstance()->getReferralWelcomeMessage($this->user->ID); |
| | | if (!empty($whatever)) { |
| | | return $whatever; |
| | | } |
| | |
| | | |
| | | protected function getIntegrationsMenu():string |
| | | { |
| | | $integrations = JVB()->getAvailableServices(false); |
| | | $integrations = $this->getAvailableServices(); |
| | | $out = ''; |
| | | if (!empty($integrations)) { |
| | | $out = '<nav class="integrations"><ul>'; |
| | | |
| | | $url = get_home_url(null, '/dash/integrations/'); |
| | | $out .= '<li><a href="'.$url.'">'.jvbDashIcon('plugs-connected').'Integrations</a></li>'; |
| | | foreach ($integrations as $name=> $integration) { |
| | | if (!JVB()->userCanConnect($name, $this->user->ID) || !$integration->hasDefaults()) { |
| | | foreach ($integrations as $service) { |
| | | $integration = $this->getService($service); |
| | | if (method_exists($integration, 'userCanConnect') && !$integration->userCanConnect($this->user->ID)) { |
| | | continue; |
| | | } |
| | | $link = sanitize_title(str_replace('_', '-',$name)); |
| | | $link = sanitize_title(str_replace('_', '-',$service)); |
| | | $out .= '<li><a href="'.$url.$link.'">'.jvbDashIcon($integration->icon).$integration->getTitle().'</a></li>'; |
| | | } |
| | | $out .= '</ul></nav>'; |
| | |
| | | if ($connection !== 'integrations') { |
| | | |
| | | $userID = (Site::has('has_membership')) ? $this->user->ID : null; |
| | | $integration = JVB()->connect($connection, $userID); |
| | | |
| | | echo '<h1>Managing '.$integration->title.'</h1>'; |
| | | $integration->renderDefaults(); |
| | | $integration = $this->getServiceUser($connection, $userID); |
| | | if (method_exists($integration, 'renderDefaults')) { |
| | | echo '<h1>Managing '.$integration->title.'</h1>'; |
| | | $integration->renderDefaults(); |
| | | } |
| | | } else { |
| | | ?> |
| | | <section class="item-grid integrations"> |
| | | <?php |
| | | $all = JVB()->getAvailableServices(); |
| | | foreach ($all as $name) { |
| | | |
| | | foreach ($this->getAvailableServices() as $name) { |
| | | if (current_user_can('manage_options')) { |
| | | $userID = null; |
| | | } else { |
| | | $userID = $this->user->ID; |
| | | } |
| | | |
| | | JVB()->connect($name, $userID)->renderConnection(); |
| | | $integration = $this->getService($name); |
| | | if (method_exists($integration, 'determineUser') |
| | | && method_exists($integration, 'renderConnection')) { |
| | | $integration->determineUser(); |
| | | $integration->renderConnection(); |
| | | } |
| | | } |
| | | ?> |
| | | </section> |
| | |
| | | $membership = Site::membership(); |
| | | $type = $registrar? $registrar->getType() : false; |
| | | if ($type) { |
| | | $permission = JVB()->roles()->getPermission('edit', $key); |
| | | $permission = Roles::getInstance()()->getPermission('edit', $key); |
| | | } |
| | | switch ($type) { |
| | | case 'content': |
| | |
| | | break; |
| | | case 'taxonomy': |
| | | $registrar = Registrar::getInstance($key); |
| | | if ($registrar && $registrar->hasFeature('is_content') && (!empty(JVB()->roles()->getOwnedTerms($userID, $key)) || !empty(JVB()->roles()->getManagedTerms($userID, $key)))){ |
| | | if ($registrar && $registrar->hasFeature('is_content') && (!empty(Roles::getInstance()()->getOwnedTerms($userID, $key)) || !empty(Roles::getInstance()()->getManagedTerms($userID, $key)))){ |
| | | $remove = false; |
| | | } else if (count(array_intersect($registrar->registrar->for, array_keys($pages))) > 0) { |
| | | $remove = false; |