| | |
| | | */ |
| | | abstract class Integrations |
| | | { |
| | | //Flag to allow for custom settings (defaults, etc) for an integration in the dashboard |
| | | public static bool $hasExtraOptions = false; |
| | | /** |
| | | * Queue types |
| | | * These types match with IntegrationExecutor |
| | | */ |
| | | protected static string $syncTo = 'sync_to'; |
| | | protected static string $deleteFrom = 'delete_from'; |
| | | protected static string $syncFrom = 'sync_from'; |
| | | protected static string $syncCustomer = 'sync_customer'; |
| | | protected static string $import = 'import'; |
| | | /** |
| | | * API Configuration |
| | | * These properties define how the integration connects to external services |
| | |
| | | * Used for UI rendering in admin interfaces |
| | | */ |
| | | public string $title; // Human-readable service name (e.g., 'Google My Business') |
| | | public string $icon; // Phosphoricons icon slug |
| | | public string $icon = ''; // Phosphoricons icon slug |
| | | |
| | | /** |
| | | * Credentials & State |
| | |
| | | protected bool $is_healthy = true; |
| | | protected bool $handleWebhooks = false; |
| | | |
| | | public function __construct(?int $userID = null) |
| | | protected function __construct(?int $userID = null) |
| | | { |
| | | $this->cacheName = $this->cacheName ?: $this->service_name; |
| | | $this->userID = $userID; |
| | |
| | | } |
| | | |
| | | add_filter('jvbShouldRenderMeta', [$this, 'checkRenderField'], 10, 4); |
| | | |
| | | |
| | | } |
| | | |
| | | protected function addFilters():bool |
| | | { |
| | | return is_null($this->userID); |
| | | } |
| | | |
| | | protected function setContentTypes():void |
| | |
| | | if (!$taxonomies) { |
| | | // Combine both content and taxonomy filtering |
| | | $taxonomies = []; |
| | | foreach (Registrar::getFeatured('is_content', 'term') as $type) { |
| | | foreach (Registrar::withFeature('is_content', 'term') as $type) { |
| | | $registrar = Registrar::getInstance($type); |
| | | if ($registrar->hasIntegration($this->service_name)) { |
| | | $taxonomies[] = $registrar->getSlug(); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Switch user context |
| | | */ |
| | | public function switchUser(int $user_id): void |
| | | { |
| | | if ($this->userID === $user_id) { |
| | | return; |
| | | } |
| | | |
| | | // Clean up current context |
| | | $this->cleanup(); |
| | | |
| | | // Switch context |
| | | $this->userID = $user_id; |
| | | $this->credentials = []; |
| | | $this->resetTokenRefreshFlag(); // ADD THIS LINE |
| | | |
| | | $this->ensureInitialized(); |
| | | } |
| | | |
| | | public function getAsUser(int $user_id) { |
| | | return new $this($user_id); |
| | | } |
| | | |
| | | /** |
| | | * Clean up resources |
| | | */ |
| | | protected function cleanup(): void |
| | | { |
| | | // Clear sensitive data |
| | | $this->credentials = []; |
| | | |
| | | // Clear request history |
| | | $this->request_history = []; |
| | | } |
| | | |
| | | /** |
| | | * Destructor - ensure cleanup |
| | | */ |
| | | public function __destruct() |
| | | { |
| | | $this->cleanup(); |
| | | } |
| | | |
| | | |
| | | /*************************************************************** |
| | | ERROR HANDLING |
| | | ***************************************************************/ |
| | |
| | | return $this->title; |
| | | } |
| | | |
| | | public static function title():string |
| | | { |
| | | return static::getInstance()->getTitle(); |
| | | } |
| | | public static function icon():string |
| | | { |
| | | return static::getInstance()->getIcon(); |
| | | } |
| | | |
| | | public static function hasExtraOptions():bool |
| | | { |
| | | return static::getInstance()::$hasExtraOptions; |
| | | } |
| | | |
| | | /********************************************************************* |
| | | RENDERING |
| | | *********************************************************************/ |
| | |
| | | return []; |
| | | } |
| | | |
| | | $key = BASE.$this->service_name.'_enabled_content_types'; |
| | | $enabled = get_option($key); |
| | | if (!$enabled) { |
| | | $enabled = []; |
| | | foreach (Registrar::getRegistered() as $registrar) { |
| | | $registrar = Registrar::getInstance($registrar); |
| | | if (!$registrar->hasIntegration($this->service_name)) { |
| | | continue; |
| | | } |
| | | $type = $registrar->getIntegration($this->service_name)->getContent_type(); |
| | | if (!$type) { |
| | | continue; |
| | | } |
| | | |
| | | if (!in_array($type, $enabled)) { |
| | | $enabled[] = $type; |
| | | } |
| | | } |
| | | update_option($key, $enabled); |
| | | } |
| | | return $enabled; |
| | | return array_filter(array_map(function($registrar) { |
| | | $registrar = Registrar::getInstance($registrar); |
| | | return $registrar->getIntegration($this->service_name)->getContentType(); |
| | | }, Registrar::withIntegration($this->service_name))); |
| | | } |
| | | |
| | | protected function getSupportedImage(int $imgID):int |
| | |
| | | { |
| | | return []; |
| | | } |
| | | |
| | | public function getIcon():string |
| | | { |
| | | return $this->icon; |
| | | } |
| | | } |