| | |
| | | use JVBase\meta\Form; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\ui\Navigation; |
| | | use WP_User; |
| | | use WP_Error;use WP_Query;use WP_User; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; // Exit if accessed directly |
| | |
| | | { |
| | | $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->connect('user'); |
| | | add_action('init', [$this, 'registerDashboard']); |
| | | if (!$this->isRegistered()) { |
| | | add_action('init', [$this, 'buildDashboard']); |
| | | } |
| | | $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.'profile_link', true); |
| | |
| | | add_action('wp_enqueue_scripts', [$this, 'dashboardScripts'], 50); |
| | | add_filter('jvbDashboardPage', [$this, 'renderIndex'], 10, 2); |
| | | |
| | | jvb_register_do_once('buildDashboard', [$this, 'activate']); |
| | | |
| | | add_filter('the_seo_framework_sitemap_exclude_ids', [$this, 'excludeDashboard'], 10, 1); |
| | | } |
| | | |
| | |
| | | * Ensures the necessary pages are created |
| | | * @return void |
| | | */ |
| | | public function buildDashboard():void |
| | | public function activate():void |
| | | { |
| | | $manageableContent = $this->getAllDashboardPages(); |
| | | error_log('[DashboardManager]::buildDashboard Manageable Content: '.print_r($manageableContent, true)); |
| | | foreach ($manageableContent as $slug => $page) { |
| | | if ($page === 'dash') { |
| | | continue; |
| | | } |
| | | $slug = $this->getSlug($slug, $page); |
| | | $existing = get_page_by_path($slug, OBJECT, BASE.'dash'); |
| | | if ($existing) { |
| | | continue; |
| | | |
| | | $ID = $this->createDashboardPage($slug, $page); |
| | | |
| | | |
| | | $registrar = Registrar::getInstance($slug); |
| | | if ($registrar) { |
| | | $create = [ |
| | | 'new_' => 'Create New ', |
| | | 'edit_' => 'Edit ' |
| | | ]; |
| | | $parentID = (int)$ID; |
| | | foreach ($create as $s => $t) { |
| | | $s .= $slug; |
| | | $t .= $page; |
| | | $this->createDashboardPage($s, $t, $parentID); |
| | | } |
| | | } |
| | | $title = $page; |
| | | |
| | | $ID = wp_insert_post(array( |
| | | 'post_title' => $title, |
| | | 'post_name' => $slug, |
| | | 'post_type' => BASE.'dash', |
| | | 'post_status' => 'publish', |
| | | )); |
| | | |
| | | if ($title === 'Integrations') { |
| | | if ($page === 'Integrations') { |
| | | $this->buildIntegrationPages($ID); |
| | | } |
| | | } |
| | | update_option(BASE.'dashboard_registered', true); |
| | | remove_action('init', [$this, 'buildDashboard']); |
| | | } |
| | | public function createDashboardPage(string $slug, string $page, int $parentID = 0):int|WP_Error |
| | | { |
| | | if (is_numeric($slug)) { |
| | | $slug = $this->getSlug($slug, $page); |
| | | } |
| | | |
| | | $existing = new WP_Query([ |
| | | 'post_type' => BASE.'dash', |
| | | 'name' => $slug, |
| | | 'fields' => 'ids', |
| | | 'posts_per_page' => 1, |
| | | ]); |
| | | |
| | | if ($existing->have_posts()) { |
| | | return $existing->posts[0]; |
| | | } |
| | | |
| | | |
| | | $args = [ |
| | | 'post_title' => $page, |
| | | 'post_name' => $slug, |
| | | 'post_type' => BASE.'dash', |
| | | 'post_status' => 'publish', |
| | | ]; |
| | | if ($parentID > 0) { |
| | | $args['post_parent'] = $parentID; |
| | | } |
| | | return wp_insert_post($args); |
| | | } |
| | | |
| | | /** |
| | | * Build integration sub-pages |
| | |
| | | |
| | | foreach ($integrations as $name => $integration) { |
| | | $title = $integration->getTitle(); |
| | | |
| | | $slug = sanitize_title($title); |
| | | |
| | | // Check if integration page already exists |
| | | $existing = get_posts([ |
| | | 'post_type' => BASE.'dash', |
| | | 'name' => $slug, |
| | | 'post_parent' => $parentID, |
| | | 'posts_per_page' => 1, |
| | | ]); |
| | | |
| | | if (!empty($existing)) { |
| | | continue; // Skip if exists |
| | | } |
| | | |
| | | wp_insert_post([ |
| | | 'post_title' => $title, |
| | | 'post_name' => $slug, |
| | | 'post_type' => BASE.'dash', |
| | | 'post_status' => 'publish', |
| | | 'post_parent' => $parentID |
| | | ]); |
| | | $this->createDashboardPage($slug, $title, $parentID); |
| | | } |
| | | } |
| | | |
| | |
| | | return $description; |
| | | } |
| | | |
| | | /** |
| | | * Checks if we've already created the need pages |
| | | * @return bool |
| | | */ |
| | | protected function isRegistered():bool |
| | | { |
| | | return get_option(BASE.'dashboard_registered', false); |
| | | } |
| | | |
| | | /** |
| | | * Hacking into the template_include to set our custom templates and protections |
| | |
| | | <body class="dashboard<?= ' '.$this->getCurrentPageSlug()?>"> |
| | | <?php jvbAccessibility();?> |
| | | <header> |
| | | <?php |
| | | $checked = (is_user_logged_in() && current_user_can('prefers_dark_theme', true)) ? ' checked' : ''; |
| | | $title = ($checked == '') ? 'Toggle Dark Mode' : 'Toggle Light Mode'; |
| | | echo '<label title="'.$title.'" id="theme-switch" class="toggle-switch" for="theme-switcher"> |
| | | <input class="theme-switch row" id="theme-switcher" name="theme-switcher" type="checkbox"'.$checked.' data-setting="theme" data-theme role="switch" name="dark-mode" aria-label="Toggle dark mode"><span class="slider">'. |
| | | jvbIcon('sun-dim', ['title'=> 'Light Mode']). |
| | | jvbIcon('moon', ['title'=>'Dark Mode']). |
| | | '</span></label>'; |
| | | ?> |
| | | <p class="title"> |
| | | <a href="<?= get_home_url(); ?>" rel="home" title="Back to Site"> |
| | | <?php |
| | | $icon = (int) get_option( 'site_icon' ); |
| | | $out = ''; |
| | | if ($icon > 0) { |
| | | $url = wp_get_attachment_image_url( $icon); |
| | | if ($url) { |
| | | $out = '<img src="'.$url.'">'; |
| | | } |
| | | } |
| | | if ($out == '') { |
| | | $out =jvbIcon('house'); |
| | | } |
| | | ?><?= $out ?> |
| | | </a> |
| | | </p> |
| | | <?= jvbDarkModeToggle() ?> |
| | | <?php |
| | | $function = BASE.'render_core_site_logo'; |
| | | if (function_exists($function)) { |
| | | echo $function([],''); |
| | | } else { |
| | | echo render_block( [ |
| | | 'blockName' => 'core/site-logo', |
| | | 'attrs' => [], |
| | | ]); |
| | | } |
| | | ?> |
| | | |
| | | <nav> |
| | | <ul> |
| | | <?= jvbNotificationMenu() ?> |
| | | <?= jvbHelpMenu() ?> |
| | | <li><a href="<?=wp_logout_url(get_home_url())?>" title="Logout"><?=jvbIcon('sign-out')?></a></li> |
| | | </ul> |
| | | </nav> |
| | | </header> |
| | | <nav> |
| | | <ul> |
| | | <?= jvbNotificationMenu() ?> |
| | | <?= jvbHelpMenu() ?> |
| | | <li><a href="<?=wp_logout_url(get_home_url())?>" title="Logout"><?=jvbIcon('sign-out')?></a></li> |
| | | </ul> |
| | | </nav> |
| | | </header> |
| | | |
| | | <main><section class="replace"> |
| | | <?php |
| | |
| | | |
| | | <?php |
| | | $menu = new Navigation('sidebar'); |
| | | $menuClasses = ['col', 'a-start', 'nowrap']; |
| | | $menuClasses = ['col', 'left', 'nowrap']; |
| | | $itemClasses = ['col']; |
| | | $menu->addClass('col a-start')->hasToggle()->defaultMenuClasses($menuClasses); |
| | | $menu->addClass('col left')->hasToggle()->defaultMenuClasses($menuClasses); |
| | | $menu->defaultItemClasses($itemClasses); |
| | | $pages = $this->getUserAllowedPages()?:[]; |
| | | //Dashboard |
| | |
| | | $itemMenu = $item->submenu($slug); |
| | | foreach ($taxonomies as $s) { |
| | | $taxRegistrar = Registrar::getInstance($s); |
| | | $itemMenu->addItem($taxRegistrar->getPlural(), $taxRegistrar->getIcon()) |
| | | if ($taxRegistrar) { |
| | | $itemMenu->addItem($taxRegistrar->getPlural(), $taxRegistrar->getIcon()) |
| | | ->url($this->baseURL.'/'.$s); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | ob_start(); |
| | | $name = ($this->user->first_name !== '') ? $this->user->first_name : $this->user->display_name; |
| | | |
| | | echo '<h1 style="text-transform:none;margin-top:2em!important;">Hey '.$name.'</h1>'; |
| | | echo '<h1>Hey '.$name.'</h1>'; |
| | | echo '<p>Welcome back!</p>'; |
| | | |
| | | $pages = $this->getUserAllowedPages(); |
| | |
| | | { |
| | | ?> |
| | | <div class="approvals container"> |
| | | <nav class="tabs row start" role="tablist"> |
| | | <nav class="tabs row left" role="tablist"> |
| | | <button type="button" class="tab active" data-tab="summary" role="tab" aria-selected="true"> |
| | | <h2><?= jvbDashIcon('infinity')?>All</h2> |
| | | <?= jvbDashIcon('infinity')?>All |
| | | </button> |
| | | <button type="button" class="tab" data-tab="artists" role="tab" aria-selected="false"> |
| | | <h2><?= jvbDashIcon('users-three')?>Artists</h2> |
| | | <?= jvbDashIcon('users-three')?>Artists |
| | | </button> |
| | | <button type="button" class="tab" data-tab="terms" role="tab" aria-selected="false"> |
| | | <h2><?= jvbDashIcon('hash')?>Terms</h2> |
| | | <?= jvbDashIcon('hash')?>Terms |
| | | </button> |
| | | <button type="button" class="tab" data-tab="yours" role="tab" aria-selected="false"> |
| | | <h2><?= jvbDashIcon('user')?>Yours</h2> |
| | | <?= jvbDashIcon('user')?>Yours |
| | | </button> |
| | | </nav> |
| | | </div> |
| | |
| | | } |
| | | ob_start(); |
| | | ?> |
| | | <nav class="tabs row start" role="tablist"> |
| | | <nav class="tabs row left" role="tablist"> |
| | | <?php |
| | | $i=1; |
| | | $content = Registrar::getRegistered('post'); |
| | |
| | | $remove = true; |
| | | if (!is_numeric($key)) { |
| | | $registrar = Registrar::getInstance($key); |
| | | $membership = Site::membership(); |
| | | $type = $registrar? $registrar->getType() : false; |
| | | if ($type) { |
| | | $permission = JVB()->roles()->getPermission('edit', $key); |