'JVBase\integrations\GoogleMaps', 'square' => 'JVBase\integrations\Square', 'facebook' => 'JVBase\integrations\Facebook', 'helcim' => 'JVBase\integrations\Helcim', 'instagram' => 'JVBase\integrations\Instagram', 'bluesky' => 'JVBase\integrations\BlueSky', 'gmb' => 'JVBase\integrations\GoogleMyBusiness', 'cloudflare' => 'JVBase\integrations\Cloudflare', 'umami' => 'JVBase\integrations\Umami', 'postmark' => 'JVBase\integrations\PostMark', ]; public static function getInstance():JVB { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } public function __construct() { $this->managers = [ 'errors' => new ErrorHandler(), 'queue' => new OperationQueue(), // 'dash' => new DashboardManager(), 'roles' => new RoleManager(), // 'forms' => new FormManager(), 'schema' => new SchemaOutputManager(), 'admin' => new AdminPages(), 'seoAdmin' => new SEOAdminPage(), // 'uploads' => new UploadManager(), 'userTerms' => new UserTermsManager(), 'email' => new EmailManager(), ]; $this->routes = [ 'login' => new LoginRoutes(), 'integrations' => new IntegrationsRoutes(), 'seo' => new SEORoutes(), 'queue' => new QueueRoutes(), 'settings' => new SettingsRoutes(), 'upload' => new UploadRoutes(), 'forms' => new FormRoutes() ]; if (Features::forSite()->has('magicLink')) { $this->routes['magicLink'] = new MagicLinkRoutes(); $this->managers['magicLink'] = new MagicLinkManager(); } if (Features::forSite()->has('referrals')) { $this->managers['referral'] = new ReferralManager(); $this->routes['referral'] = new ReferralRoutes(); } if (Features::forSite()->has('dashboard')) { $this->managers['dash'] = new DashboardManager(); } if (Features::hasIntegration('square')){ $this->routes['square'] = new IntegrationsSquareRoutes(); } if (Features::forSite()->has('feed_block')) { $this->routes['feed'] = new FeedRoutes(); } if (jvbSiteHasNotifications()) { $this->managers['notifications'] = new NotificationManager(); $this->routes['notifications'] = new NotificationsRoutes(); } if (Features::forSite()->has('feed_block') || jvbSiteHasDashboard()) { $this->routes['term'] = new TermRoutes(); } if (jvbSiteHasDashboard()) { $this->routes['error'] = new ErrorRoutes(); $this->routes['admin'] = new AdminRoutes(); $this->routes['content']= new ContentRoutes(); $this->routes['bio'] = new BioRoutes(); $this->routes['shop'] = new ShopRoutes(); $this->routes['options']= new OptionsRoutes(); } if (jvbSiteHasFavourites()) { $this->routes['favourites'] = new FavouritesRoutes(); } if (Features::forMembership()->has('forum')) { $this->routes['news'] = new NewsRoutes(); } if (Features::anyContentHas('response') || Features::anyTaxonomyHas('response') || Features::anyUserHas('response')) { $this->routes['comments'] = new ResponseRoutes(); } if (Features::anyContentHas('karma') || Features::anyTaxonomyHas('karma') || Features::anyUserHas('karma')) { $this->routes['vote'] = new VoteRoutes(); } if (Features::anyContentHas('karma') || Features::anyTaxonomyHas('karma') || Features::anyUserHas('karma') || Features::forMembership()->has('member_verified') || Features::forMembership()->has('term_approval')) { $this->routes['approvals'] = new ApprovalRoutes(); } if (Features::forMembership()->has('can_invite')) { $this->routes['invites'] = new Invitations(); } $this->setupIntegrations(); add_action('wp_footer', [$this, 'additionalActions']); // $this->managers['notifications'] = new NotificationManager(); // Register activation hook register_activation_hook(JVB_DIR . '/jvb.php', [$this, 'activate']); } protected function setupIntegrations():void { if (array_key_exists('integrations', JVB_SITE)){ foreach (JVB_SITE['integrations'] as $service => $use){ if (!$use) { continue; } if (array_key_exists($service, $this->serviceMap)) { $this->integrations[$service] = new $this->serviceMap[$service](); } } } } public function registeredContent():array { return array_merge(array_keys($this->content), array_keys($this->taxonomies)); } public function dashboard() { return $this->managers['dash']; } public function error() { return $this->managers['errors']; } public function file() { return $this->managers['file']; } public function cache() { return $this->managers['cache']; } public function queue() { return $this->managers['queue']; } // public function forms() // { // return $this->managers['forms']; // } public function notification() { return $this->managers['notifications']; } public function routes($route):mixed { if (array_key_exists($route, $this->routes)) { return $this->routes[$route]; } return false; } public function roles() { return $this->managers['roles']; } public function admin() { return $this->managers['admin']; } public function seoAdmin() { return $this->managers['seoAdmin']; } public function getFields($type):array { $content = JVB_CONTENT[$type]??JVB_TAXONOMY[$type]??JVB_USER[$type]??[]; return $content['fields']??[]; } public function getContent($type):mixed { return $this->content[$type]??$this->taxonomies[$type]??$this->blocks[$type]??null; } public function connect(string $service, ?int $userID = null):mixed { if ($userID) { if (!$this->userCanConnect($service, $userID)){ return null; } if (!array_key_exists($service, $this->integrations)) { return null; } return new $this->serviceMap[$service]($userID); } return (array_key_exists($service, $this->integrations)) ? $this->integrations[$service] : null; } public function userCanConnect(string $service, int $userID):bool { $allowed = JVB_USER[jvbUserRole($userID)]['integrations'] ?? []; return user_can($userID, 'manage_options') || in_array($service, $allowed); } public function getAvailableServices(bool $keys = true):array { return ($keys) ? array_keys($this->integrations) : $this->integrations; } public function activate():void { // Activate roles - will be properly initialized after post types are registered $this->roles()->activate(); } public function addRoute($slug, $class):void { $this->routes[$slug] = $class; } public function email():EmailManager { return $this->managers['email']; } public function referrals():ReferralManager|false { return $this->managers['referral']??false; } public function magicLink():MagicLinkManager|false { return $this->managers['magicLink']??false; } public function additionalActions():void { if (LoginManager::isLogin()) { return; } $extras = apply_filters('jvbAdditionalActions', []); $extras = array_filter($extras, function ($extra) { return is_array($extra) && array_key_exists('button', $extra) && array_key_exists('content', $extra); }); if (empty ($extras)) { return; } $buttons = array_map(function ($extra) { return $extra['button']; }, $extras); $contents = array_map(function($extra) { return $extra['content']; }, $extras); if (!empty ($buttons)) { ?>