| | |
| | | |
| | | use JVBase\blocks\CustomBlocks; |
| | | use JVBase\base\Site; |
| | | use JVBase\managers\ApprovalManager; |
| | | use JVBase\managers\EmailManager; |
| | | use JVBase\managers\ErrorHandler; |
| | | use JVBase\managers\FavouritesManager; |
| | | use JVBase\managers\InvitationsManager; |
| | | use JVBase\managers\LoginManager; |
| | | use JVBase\managers\MagicLinkManager; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\managers\DashboardManager; |
| | | use JVBase\managers\Dashboard\DashboardManager; |
| | | use JVBase\managers\DirectoryManager; |
| | | use JVBase\managers\ReferralManager; |
| | | use JVBase\managers\RoleManager; |
| | |
| | | use JVBase\rest\routes\AdminRoutes; |
| | | use JVBase\rest\routes\IntegrationsRoutes; |
| | | use JVBase\base\SchemaHelper; |
| | | use UserRoutes; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | } |
| | | |
| | | |
| | | public function __construct() |
| | | private function __construct() |
| | | { |
| | | $this->customBlocks = new CustomBlocks(); |
| | | $this->managers = [ |
| | |
| | | 'queue' => new QueueRoutes(), |
| | | 'settings' => new SettingsRoutes(), |
| | | 'upload' => new UploadRoutes(), |
| | | 'forms' => new FormRoutes() |
| | | 'forms' => new FormRoutes(), |
| | | 'user' => new UserRoutes() |
| | | ]; |
| | | |
| | | if (Site::has('magicLink')) { |
| | | if (Site::has('magic_link')) { |
| | | // $this->routes['magicLink'] = new MagicLinkRoutes(); |
| | | $this->managers['magicLink'] = new MagicLinkManager(); |
| | | } |
| | |
| | | $this->routes['referral'] = new ReferralRoutes(); |
| | | } |
| | | |
| | | if (Site::has('dashboard')) { |
| | | $this->managers['dash'] = new DashboardManager(); |
| | | } |
| | | |
| | | if (Site::hasIntegration('square')) { |
| | | $this->routes['square'] = new IntegrationsSquareRoutes(); |
| | |
| | | $this->managers['notifications'] = new NotificationManager(); |
| | | $this->routes['notifications'] = new NotificationsRoutes(); |
| | | } |
| | | if (!empty(Registrar::withFeature('approve_new'))) { |
| | | $this->managers['approvals'] = new ApprovalManager(); |
| | | } |
| | | if (Site::has('feed_block') || Site::has('dashboard')) { |
| | | $this->routes['term'] = new TermRoutes(); |
| | | } |
| | |
| | | } |
| | | |
| | | if (Site::has('favourites')) { |
| | | $this->managers['favourites'] = new FavouritesManager(); |
| | | $this->routes['favourites'] = new FavouritesRoutes(); |
| | | } |
| | | |
| | |
| | | if ($membership && $membership->has('invitable')) { |
| | | $this->managers['invitations'] = new InvitationsManager(); |
| | | } |
| | | if (!empty(Registrar::getFeatured('has_responses'))) { |
| | | if (!empty(Registrar::withFeature('has_responses'))) { |
| | | $this->routes['comments'] = new ResponseRoutes(); |
| | | } |
| | | if (!empty(Registrar::getFeatured('karma'))) { |
| | | if (!empty(Registrar::withFeature('karma'))) { |
| | | $this->routes['vote'] = new VoteRoutes(); |
| | | } |
| | | if (!empty(Registrar::getFeatured('karma')) |
| | | if (!empty(Registrar::withFeature('karma')) |
| | | || ($membership && $membership->has('member_verified')) || |
| | | ($membership && $membership->has('term_approval'))) { |
| | | $this->routes['approvals'] = new ApprovalRoutes(); |
| | |
| | | $this->routes['invites'] = new Invitations(); |
| | | } |
| | | |
| | | |
| | | if (Site::has('dashboard')) { |
| | | $this->managers['dash'] = new DashboardManager(); |
| | | } |
| | | |
| | | $this->setupIntegrations(); |
| | | |
| | | add_action('wp_footer', [$this, 'additionalActions']); |
| | |
| | | protected function setupIntegrations(): void |
| | | { |
| | | foreach(array_keys(Site::getIntegrations()) as $integration) { |
| | | $this->integrations[$integration] = new $this->serviceMap[$integration](); |
| | | $this->integrations[$integration] = $this->serviceMap[$integration]::getInstance(); |
| | | } |
| | | } |
| | | |
| | |
| | | return array_merge(array_keys($this->content), array_keys($this->taxonomies)); |
| | | } |
| | | |
| | | public function favourites(): FavouritesManager|false |
| | | { |
| | | return $this->managers['favourites'] ?? false; |
| | | } |
| | | |
| | | public function dashboard(): DashboardManager|false |
| | | { |
| | | return $this->managers['dash'] ?? false; |
| | |
| | | |
| | | 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; |
| | | // if ($userID) { |
| | | // if (!$this->userCanConnect($service, $userID)) { |
| | | // return null; |
| | | // } |
| | | // |
| | | // if (!array_key_exists($service, $this->integrations)) { |
| | | // return null; |
| | | // } |
| | | // |
| | | // return $this->serviceMap[$service]::getInstance($userID); |
| | | // } |
| | | return is_null($userID) ? |
| | | $this->integrations[$service]??null : |
| | | (array_key_exists($service, $this->integrations) ? $this->serviceMap[$service]::getInstance($userID) : 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); |
| | | $role = jvbUserRole($userID); |
| | | $registrar = Registrar::getInstance($role); |
| | | return user_can($userID, 'manage_options') || $registrar->hasIntegration($service); |
| | | } |
| | | |
| | | public function getAvailableServices(bool $keys = true): array |
| | |
| | | |
| | | if (!empty ($buttons)) { |
| | | ?> |
| | | <section class="additional-actions"> |
| | | <section class="main-actions"> |
| | | <div class="buttons col"> |
| | | <?= implode($buttons); ?> |
| | | <?= implode('', $buttons); ?> |
| | | </div> |
| | | <div class="actions"> |
| | | <?= implode($contents); ?> |
| | | <?= implode('', $contents); ?> |
| | | </div> |
| | | </section> |
| | | <?php |
| | |
| | | { |
| | | return $this->managers['terms']; |
| | | } |
| | | |
| | | public function approvals ():ApprovalManager|false |
| | | { |
| | | return $this->managers['approvals']??false; |
| | | } |
| | | } |