service = new ContaiPublisuitesService(); } public function render(): void { $this->enqueueScripts(); if (!contai_has_active_license()) { $this->renderLicenseRequired(); return; } $view_data = $this->buildViewData(); $this->renderFlashMessage(); $this->renderContent($view_data); } /** * Build a fully-resolved ViewModel for the template layer. * * Keys returned: * - status_key string 'not_connected' | 'pending_verification' | 'connected' | 'error' | 'website_required' * - status_label string Human-readable badge text * - status_class string CSS modifier class for the badge * - primary_cta_label string Main action button label * - primary_cta_action string Form input name for the main CTA * - secondary_cta_label string|null Optional secondary action label * - secondary_cta_action string|null Optional secondary form input name * - site_url string Current site URL * - config array|null Raw Publisuites config * - verification_file_exists bool * - nonce_action string * - nonce_field string * - benefits array Benefit card data * - message string Contextual message from backend */ private function buildViewData(): array { $status = $this->service->initializeStatus(); $config = $status['config']; $site_url = $this->service->getSiteUrl(); $base = [ 'site_url' => $site_url, 'config' => $config, 'nonce_action' => self::NONCE_ACTION, 'nonce_field' => self::NONCE_FIELD, 'verification_file_exists' => false, 'benefits' => $this->getBenefits(), 'message' => '', 'secondary_cta_label' => null, 'secondary_cta_action' => null, ]; switch ($status['status']) { case 'website_required': return array_merge($base, [ 'status_key' => 'website_required', 'status_label' => __('Setup Required', '1platform-content-ai'), 'status_class' => 'contai-badge--warning', 'primary_cta_label' => null, 'primary_cta_action'=> null, 'message' => $status['message'] ?? __('Website registration is required before connecting to the marketplace.', '1platform-content-ai'), ]); case 'not_connected': return array_merge($base, [ 'status_key' => 'not_connected', 'status_label' => __('Not Connected', '1platform-content-ai'), 'status_class' => 'contai-badge--neutral', 'primary_cta_label' => __('Connect to Marketplace', '1platform-content-ai'), 'primary_cta_action'=> 'contai_setup_publisuites', ]); case 'configured': if ($this->service->isVerified($config)) { $marketplaceStatus = $config['marketplace_status'] ?? null; if ($marketplaceStatus !== 'active') { return array_merge($base, [ 'status_key' => 'marketplace_pending', 'status_label' => __('Pending Approval', '1platform-content-ai'), 'status_class' => 'contai-badge--warning', 'primary_cta_label' => null, 'primary_cta_action' => null, 'secondary_cta_label' => __('Remove from Marketplace', '1platform-content-ai'), 'secondary_cta_action' => 'contai_delete_from_marketplace', ]); } $view_data = array_merge($base, [ 'status_key' => 'connected', 'status_label' => __('Connected', '1platform-content-ai'), 'status_class' => 'contai-badge--success', 'primary_cta_label' => null, 'primary_cta_action' => null, 'secondary_cta_label' => __('Disconnect', '1platform-content-ai'), 'secondary_cta_action' => 'contai_disconnect_publisuites', ]); $page = isset($_GET['ps_page']) ? absint($_GET['ps_page']) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $ordersResponse = $this->service->getOrders($page); if ($ordersResponse->isSuccess()) { $ordersData = $ordersResponse->getData(); $view_data['orders'] = $ordersData['orders'] ?? []; $view_data['total'] = $ordersData['total'] ?? 0; $view_data['page'] = $ordersData['page'] ?? 1; $view_data['page_size'] = $ordersData['page_size'] ?? 20; $view_data['last_synced_at'] = $ordersData['last_synced_at'] ?? null; $view_data['stale'] = $ordersData['stale'] ?? false; } else { $view_data['orders'] = []; $view_data['total'] = 0; $view_data['page'] = 1; $view_data['page_size'] = 20; $view_data['last_synced_at'] = null; $view_data['stale'] = true; } return $view_data; } return array_merge($base, [ 'status_key' => 'pending_verification', 'status_label' => __('Pending Verification', '1platform-content-ai'), 'status_class' => 'contai-badge--warning', 'primary_cta_label' => __('Verify Website', '1platform-content-ai'), 'primary_cta_action' => 'contai_verify_publisuites', 'secondary_cta_label' => __('Disconnect', '1platform-content-ai'), 'secondary_cta_action' => 'contai_disconnect_publisuites', 'verification_file_exists' => $this->service->verificationFileExists(), ]); default: return array_merge($base, [ 'status_key' => 'error', 'status_label' => __('Error', '1platform-content-ai'), 'status_class' => 'contai-badge--error', 'primary_cta_label' => null, 'primary_cta_action'=> null, 'message' => __('An unexpected error occurred. Please try again.', '1platform-content-ai'), ]); } } private function getBenefits(): array { return [ [ 'icon' => 'dashicons-money-alt', 'title' => __('Monetize Content', '1platform-content-ai'), 'description' => __('Earn revenue by publishing sponsored posts from premium brands.', '1platform-content-ai'), ], [ 'icon' => 'dashicons-chart-line', 'title' => __('Track Performance', '1platform-content-ai'), 'description' => __('Monitor your earnings and campaign performance in real-time.', '1platform-content-ai'), ], [ 'icon' => 'dashicons-shield-alt', 'title' => __('Secure Integration', '1platform-content-ai'), 'description' => __('Verified connection with industry-standard security protocols.', '1platform-content-ai'), ], ]; } private function renderContent(array $view_data): void { switch ($view_data['status_key']) { case 'not_connected': $section = new ContaiPublisuitesConnectSection($view_data); $section->render(); break; case 'pending_verification': $section = new ContaiPublisuitesVerificationSection($view_data); $section->render(); break; case 'marketplace_pending': $section = new ContaiPublisuitesMarketplacePendingSection($view_data); $section->render(); break; case 'connected': $ordersSection = new ContaiPublisuitesOrdersSection($view_data); $ordersSection->render(); $section = new ContaiPublisuitesConnectedSection($view_data); $section->render(); break; case 'website_required': case 'error': default: $this->renderAlert($view_data); break; } } private function renderAlert(array $view_data): void { $is_error = ($view_data['status_key'] === 'error'); $box_class = $is_error ? 'contai-notice contai-notice-error' : 'contai-notice contai-notice-warning'; $icon = $is_error ? 'dashicons-warning' : 'dashicons-info-outline'; $heading = $is_error ? __('Something went wrong', '1platform-content-ai') : __('Website Registration Required', '1platform-content-ai'); ?>

'dashicons-yes-alt', 'error' => 'dashicons-warning', 'warning' => 'dashicons-info-outline', 'info' => 'dashicons-info-outline', ]; ?>

[Ref: ]