| | |
| | | |
| | | use Exception; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\managers\UploadManager; |
| | | use JVBase\registrar\Registrar; |
| | | use WP_Error; |
| | |
| | | * These properties define how the integration connects to external services |
| | | */ |
| | | protected string|array $apiBase = ''; // Base URL(s) for API endpoints. Array format: ['base' => '', 'auth' => ''] |
| | | /** |
| | | * @var array<APIEndpoint> An array of endpoints objects, with optional create, update, delete, batch<x>, and batchImport |
| | | */ |
| | | protected array $apiEndpoints = []; // Valid endpoint paths for this service |
| | | |
| | | protected int $refresh_interval = 0; //seconds before expiry to refresh tokens. 0 to disable |
| | |
| | | $this->userID = $userID; |
| | | $this->cache = Cache::for('integrations_' . $this->cacheName); |
| | | |
| | | |
| | | $this->getPostTypes(); |
| | | $this->getTaxonomies(); |
| | | $this->getUsers(); |
| | |
| | | |
| | | return $this->response(false, 'Failed to save credentials to database'); |
| | | |
| | | } catch (\Exception $e) { |
| | | } catch (Exception $e) { |
| | | // Revert to old credentials on any error |
| | | $old = Auth::getInstance()->getCredentials( |
| | | $this->service_name, |
| | |
| | | } |
| | | |
| | | try { |
| | | if ($this->isOAuthService && !$this->hasOAuthCredentials()){ |
| | | if (!$this->hasOAuthCredentials()){ |
| | | //If this is an OAuth service, we might only be saving the app credentials first |
| | | $result = true; |
| | | } else { |
| | |
| | | array $data, |
| | | array $options = [] |
| | | ):bool { |
| | | $queue = JVB()->queue(); |
| | | $queue = Queue::getInstance(); |
| | | |
| | | $queued = $queue->queueOperation( |
| | | $type, |
| | |
| | | |
| | | |
| | | if (!empty($this->syncPostTypes)) { |
| | | $this->addSavePost(); |
| | | add_action('transition_post_status', [$this, 'handlePostStatusTransition'], 10, 3); |
| | | if (method_exists($this, 'addSavePost')) { |
| | | $this->addSavePost(); |
| | | } |
| | | |
| | | // add_action('transition_post_status', [$this, 'handlePostStatusTransition'], 10, 3); |
| | | |
| | | if ($this->canSync['delete']) { |
| | | add_action('before_delete_post', [$this, 'handleDeletePost'], 10, 1); |
| | |
| | | 'message' => 'Connection established successfully' |
| | | ]; |
| | | |
| | | } catch (\Exception $e) { |
| | | } catch (Exception $e) { |
| | | return [ |
| | | 'success' => false, |
| | | 'message' => 'Error: ' . $e->getMessage() |
| | |
| | | |
| | | public function hasOAuthCredentials(?int $userID = null): bool |
| | | { |
| | | if ($userID !== $this->userID) { |
| | | $this->switchUser($userID); |
| | | } |
| | | return $this->hasOAuth && $this->hasValidOAuth(); |
| | | return false; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | public static function hasExtraOptions():bool |
| | | { |
| | | return static::getInstance()::$hasExtraOptions; |
| | | return self::$hasExtraOptions; |
| | | } |
| | | |
| | | /** |
| | |
| | | if ($jpegVersion !== '' && is_int($jpegVersion)) { |
| | | return $jpegVersion; |
| | | } |
| | | $uploader = new UploadManager(); |
| | | $converted = $uploader->convertImageTo($imgID, 'jpeg', 80, false); |
| | | $uploader = UploadManager::getInstance(); |
| | | $converted = $uploader->convertImageTo($imgID, 'jpeg'); |
| | | if ($converted && !is_wp_error($converted)) { |
| | | update_post_meta($imgID, BASE . 'jpeg_version', $converted['attachment_id']); |
| | | return $converted['attachment_id']; |
| | |
| | | |
| | | /** |
| | | * Used by JVBase\registrar\helpers\AddIntegrationFields.php |
| | | * @param string|null $content_type |
| | | * @return array |
| | | */ |
| | | public function getAdditionalFields(?string $content_type = null):array |