class-content-box-large.php
1 month ago
class-encryption-notice.php
1 month ago
class-enhancement-settings-component.php
1 month ago
class-feature-request-box.php
1 month ago
class-input-api-key.php
1 month ago
class-input-checkbox.php
1 month ago
class-link-box.php
1 month ago
class-modal-feedback.php
1 month ago
class-modal.php
1 month ago
class-navigation.php
1 month ago
class-newsletter-form.php
1 month ago
class-outdated-browser-warning.php
1 month ago
class-premium-box.php
1 month ago
class-premium-feature-list.php
1 month ago
class-review-box.php
1 month ago
class-support-box.php
1 month ago
class-support-link-boxes.php
1 month ago
class-input-api-key.php
92 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Components\Admin; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | class InputApiKey |
| 8 | { |
| 9 | private $Id; |
| 10 | private $Integration; |
| 11 | private $Title; |
| 12 | private $Description; |
| 13 | private $DashboardUrl; |
| 14 | private $DashboardLabel; |
| 15 | private $Configured; |
| 16 | private $MaskedKey; |
| 17 | private $Placeholder; |
| 18 | private $IconPath; |
| 19 | |
| 20 | /** |
| 21 | * @param string $id HTML element ID prefix (used for input, save btn, remove btn, spinner). |
| 22 | * @param string $integration Integration slug sent to the REST API (e.g. "mailchimp", "brevo"). |
| 23 | * @param string $title Heading label. |
| 24 | * @param string $description Help text shown below the heading. |
| 25 | * @param string $dashboard_url URL to the provider's dashboard for obtaining API keys. |
| 26 | * @param string $dashboard_label Link text for the dashboard URL. |
| 27 | * @param bool $configured Whether an API key is currently stored. |
| 28 | * @param string $masked_key Masked representation of the stored key. |
| 29 | * @param string $placeholder Placeholder text for the input field. |
| 30 | */ |
| 31 | public function __construct($id, $integration, $title, $description, $dashboard_url, $dashboard_label, $configured, $masked_key = '', $placeholder = '') |
| 32 | { |
| 33 | $this->Id = $id; |
| 34 | $this->Integration = $integration; |
| 35 | $this->Title = $title; |
| 36 | $this->Description = $description; |
| 37 | $this->DashboardUrl = $dashboard_url; |
| 38 | $this->DashboardLabel = $dashboard_label; |
| 39 | $this->Configured = $configured; |
| 40 | $this->MaskedKey = $masked_key; |
| 41 | $this->Placeholder = $placeholder; |
| 42 | |
| 43 | switch ($integration) { |
| 44 | case 'mailchimp': |
| 45 | $this->IconPath = SUPERBADDONS_ASSETS_PATH . '/img/mailchimp-icon.svg'; |
| 46 | break; |
| 47 | case 'brevo': |
| 48 | $this->IconPath = SUPERBADDONS_ASSETS_PATH . '/img/brevo-icon.svg'; |
| 49 | break; |
| 50 | default: |
| 51 | $this->IconPath = SUPERBADDONS_ASSETS_PATH . '/img/purple-plugs.svg'; |
| 52 | } |
| 53 | |
| 54 | $this->Render(); |
| 55 | } |
| 56 | |
| 57 | private function Render() |
| 58 | { |
| 59 | ?> |
| 60 | <div class="superbaddons-integration-card <?php echo $this->Configured ? 'superbaddons-integration-card--connected' : ''; ?>" data-integration="<?php echo esc_attr($this->Integration); ?>"> |
| 61 | <div class="superbaddons-integration-card-header"> |
| 62 | <img class="superbaddons-integration-card-logo" src="<?php echo esc_url($this->IconPath); ?>" /> |
| 63 | <h5 class="superbaddons-element-text-xs superbaddons-element-text-gray superbaddons-element-text-800 superbaddons-element-m0"><?php echo esc_html($this->Title); ?></h5> |
| 64 | <?php if ($this->Configured) : ?> |
| 65 | <span class="superbaddons-integration-card-badge superbaddons-integration-card-badge--connected"><?php echo esc_html__("Connected", "superb-blocks"); ?></span> |
| 66 | <?php else : ?> |
| 67 | <span class="superbaddons-integration-card-badge"><?php echo esc_html__("Not Connected", "superb-blocks"); ?></span> |
| 68 | <?php endif; ?> |
| 69 | </div> |
| 70 | <div class="superbaddons-integration-card-body"> |
| 71 | <?php if ($this->Configured) : ?> |
| 72 | <div class="superbaddons-integration-card-connected-info"> |
| 73 | <code class="superbaddons-input-api-key-masked"><?php echo esc_html($this->MaskedKey); ?></code> |
| 74 | <button type="button" class="superbaddons-element-button spbaddons-admin-btn-danger superbaddons-element-button-sm superbaddons-input-api-key-remove-btn" id="<?php echo esc_attr($this->Id); ?>-remove-btn"><img class="superbaddons-element-button-icon" src="<?php echo esc_url(SUPERBADDONS_ASSETS_PATH . '/img/trash-light.svg'); ?>" /><?php echo esc_html__("Disconnect", "superb-blocks"); ?></button> |
| 75 | </div> |
| 76 | <?php else : ?> |
| 77 | <p class="superbaddons-element-text-xxs superbaddons-element-text-gray superbaddons-integration-card-description"><?php echo esc_html($this->Description); ?></p> |
| 78 | <div class="superbaddons-input-api-key-input-row"> |
| 79 | <input id="<?php echo esc_attr($this->Id); ?>-input" type="text" class="superbaddons-input-api-key-input superbaddons-input-masked" placeholder="<?php echo esc_attr($this->Placeholder); ?>" autocomplete="off" /> |
| 80 | <button type="button" class="superbaddons-element-button superbaddons-element-button-sm superbaddons-input-api-key-save-btn" id="<?php echo esc_attr($this->Id); ?>-save-btn" disabled><?php echo esc_html__("Connect", "superb-blocks"); ?></button> |
| 81 | </div> |
| 82 | <div class="superbaddons-spinner-wrapper superbaddons-input-api-key-spinner" id="<?php echo esc_attr($this->Id); ?>-spinner" style="display:none;"> |
| 83 | <img class="spbaddons-spinner" src="<?php echo esc_url(SUPERBADDONS_ASSETS_PATH . "/img/blocks-spinner.svg"); ?>" /> |
| 84 | </div> |
| 85 | <p class="superbaddons-element-text-xxs superbaddons-element-text-gray"><a href="<?php echo esc_url($this->DashboardUrl); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html($this->DashboardLabel); ?></a></p> |
| 86 | <?php endif; ?> |
| 87 | </div> |
| 88 | </div> |
| 89 | <?php |
| 90 | } |
| 91 | } |
| 92 |