class-evf-builder-fields.php
2 weeks ago
class-evf-builder-integrations.php
2 weeks ago
class-evf-builder-page.php
2 months ago
class-evf-builder-payments.php
2 weeks ago
class-evf-builder-settings.php
3 months ago
class-evf-builder-integrations.php
183 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Builder Integrations |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @since |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * EVF_Builder_Integrations class. |
| 13 | */ |
| 14 | if ( ! class_exists( 'EVF_Builder_Integrations' ) ) { |
| 15 | |
| 16 | class EVF_Builder_Integrations extends EVF_Builder_Page { |
| 17 | |
| 18 | /** |
| 19 | * Constructor. |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | $this->id = 'integrations'; |
| 23 | $this->label = __( 'Integrations', 'everest-forms' ); |
| 24 | $this->sidebar = true; |
| 25 | |
| 26 | parent::__construct(); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Outputs the builder sidebar. |
| 31 | */ |
| 32 | public function output_sidebar() { |
| 33 | $integrations = apply_filters( 'everest_forms_available_integrations', array() ); |
| 34 | |
| 35 | if ( ! defined( 'EFP_PLUGIN_FILE' ) ) { |
| 36 | $integrations = $this->get_free_integrations_catalog(); |
| 37 | } |
| 38 | |
| 39 | if ( ! empty( $integrations ) ) { |
| 40 | foreach ( $integrations as $integration ) { |
| 41 | if ( ! defined( 'EFP_PLUGIN_FILE' ) ) { |
| 42 | $pro_icon = plugins_url( 'assets/images/icons/evf-pro-icon.png', EVF_PLUGIN_FILE ); |
| 43 | $video_id = isset( $integration['video_id'] ) ? $integration['video_id'] : ( isset( $integration['vedio_id'] ) ? $integration['vedio_id'] : '' ); |
| 44 | echo '<a href="#" class="integration-name evf-panel-tab evf-integrations-panel everest-forms-panel-sidebar-section everest-forms-panel-sidebar-section-' . esc_attr( $integration['id'] ) . ' upgrade-addons-settings" data-section="' . esc_attr( $integration['id'] ) . '" data-name="' . esc_attr( $integration['name'] ) . '" data-links="' . esc_attr( $video_id ) . '">'; |
| 45 | |
| 46 | echo '<div style="display: flex; align-items: center; gap: 12px;">'; |
| 47 | if ( ! empty( $integration['icon'] ) ) { |
| 48 | echo '<figure class="logo"><img src="' . esc_url( $integration['icon'] ) . '"></figure>'; |
| 49 | } |
| 50 | echo '<span>' . esc_html($integration['name']) . '</span>'; |
| 51 | echo '</div>'; |
| 52 | echo '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18"><rect width="16.889" height="16.889" x=".444" y=".444" fill="#ff8c39" stroke="#ff8c39" stroke-width=".889" rx="2.222"/><path fill="#efefef" d="m8.89 4.444 2.666 7.111H6.223z"/><path fill="#fff" fill-rule="evenodd" d="m4.445 6.222.635 5.333h7.619l.635-5.333-4.445 3.666zm8.254 5.841h-7.62v1.27h7.62z" clip-rule="evenodd"/></svg>'; |
| 53 | echo '</a>'; |
| 54 | |
| 55 | } else { |
| 56 | $this->add_sidebar_tab( $integration['name'], $integration['id'], $integration['icon'], $this->id ); |
| 57 | do_action( 'everest_forms_integration_connections_' . $integration['id'], $integration ); |
| 58 | } |
| 59 | } |
| 60 | } elseif ( defined( 'EFP_PLUGIN_FILE' ) ) { |
| 61 | $addons_url = admin_url( 'admin.php?page=evf-addons' ); |
| 62 | foreach ( $this->get_free_integrations_catalog() as $integration ) { |
| 63 | echo '<a href="#" ' |
| 64 | . 'class="integration-name evf-panel-tab evf-integrations-panel everest-forms-panel-sidebar-section everest-forms-panel-sidebar-section-' . esc_attr( $integration['id'] ) . ' evf-addon-install-trigger" ' |
| 65 | . 'style="opacity: 0.65;" ' |
| 66 | . 'data-section="' . esc_attr( $integration['id'] ) . '" ' |
| 67 | . 'data-name="' . esc_attr( $integration['name'] ) . '" ' |
| 68 | . 'data-slug="' . esc_attr( $integration['slug'] ) . '" ' |
| 69 | . 'data-description="' . esc_attr( $integration['excerpt'] ) . '" ' |
| 70 | . 'data-addons-url="' . esc_url( $addons_url ) . '">'; |
| 71 | echo '<div style="display: flex; align-items: center; gap: 12px;">'; |
| 72 | if ( ! empty( $integration['icon'] ) ) { |
| 73 | echo '<figure class="logo" style="filter: grayscale(50%);"><img src="' . esc_url( $integration['icon'] ) . '"></figure>'; |
| 74 | } |
| 75 | echo '<span>' . esc_html( $integration['name'] ) . '</span>'; |
| 76 | echo '</div>'; |
| 77 | echo '<span style="font-size: 10px; font-weight: 600; color: #888; background: #e1e1e1; border-radius: 3px; padding: 2px 6px; text-transform: uppercase; letter-spacing: 0.3px; white-space: nowrap;">' . esc_html__( 'Inactive', 'everest-forms' ) . '</span>'; |
| 78 | echo '</a>'; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get free integrations catalog from extensions JSON. |
| 85 | * |
| 86 | * @return array |
| 87 | */ |
| 88 | private function get_free_integrations_catalog() { |
| 89 | $catalog = array(); |
| 90 | $file = dirname( EVF_PLUGIN_FILE ) . '/assets/extensions-json/sections/all_extensions.json'; |
| 91 | |
| 92 | if ( file_exists( $file ) ) { |
| 93 | $content = file_get_contents( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 94 | $data = json_decode( $content, true ); |
| 95 | |
| 96 | if ( isset( $data['products'] ) && is_array( $data['products'] ) ) { |
| 97 | $data['features'] = isset( $data['features'] ) && is_array( $data['features'] ) ? $data['features'] : array(); |
| 98 | $items = array_merge( $data['products'], $data['features'] ); |
| 99 | |
| 100 | foreach ( $items as $item ) { |
| 101 | $category = isset( $item['category'] ) ? $item['category'] : ''; |
| 102 | if ( ! in_array( $category, array( 'Integrations', 'Email Marketing', 'CRM Integrations' ), true ) ) { |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | $slug = isset( $item['slug'] ) ? $item['slug'] : ''; |
| 107 | |
| 108 | // Email Templates belongs to the admin sidebar; SMS Notifications is managed via the Settings tab. |
| 109 | if ( in_array( $slug, array( 'everest-forms-email-templates', 'everest-forms-sms-notifications' ), true ) ) { |
| 110 | continue; |
| 111 | } |
| 112 | |
| 113 | $id = str_replace( 'everest-forms-', '', $slug ); |
| 114 | $name = isset( $item['name'] ) ? $item['name'] : ''; |
| 115 | $name = str_replace( 'Everest Forms - ', '', $name ); |
| 116 | $name = str_replace( 'Everest Forms- ', '', $name ); |
| 117 | $name = str_replace( 'Everest Forms-', '', $name ); |
| 118 | $name = str_replace( 'Everest Forms ', '', $name ); |
| 119 | $name = trim( $name ); |
| 120 | |
| 121 | $image = isset( $item['image'] ) ? $item['image'] : ''; |
| 122 | $icon = ! empty( $image ) ? plugins_url( 'assets/' . ltrim( $image, '/' ), EVF_PLUGIN_FILE ) : ''; |
| 123 | |
| 124 | $catalog[ $id ] = array( |
| 125 | 'id' => $id, |
| 126 | 'slug' => $slug, |
| 127 | 'name' => $name, |
| 128 | 'icon' => $icon, |
| 129 | 'video_id' => isset( $item['demo_video_url'] ) ? $item['demo_video_url'] : '', |
| 130 | 'excerpt' => isset( $item['excerpt'] ) ? $item['excerpt'] : '', |
| 131 | ); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return array_values( $catalog ); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Outputs the builder content. |
| 141 | */ |
| 142 | public function output_content() { |
| 143 | $providers_active = apply_filters( 'everest_forms_available_integrations', array() ); |
| 144 | |
| 145 | if ( empty( $providers_active ) ) { |
| 146 | if ( defined( 'EFP_PLUGIN_FILE' ) ) { |
| 147 | $addons_url = admin_url( 'admin.php?page=evf-addons' ); |
| 148 | echo '<div class="evf-panel-content-section evf-panel-content-section-info evf-builder-get-started">'; |
| 149 | echo '<h3>' . esc_html__( 'No integrations activated', 'everest-forms' ) . '</h3>'; |
| 150 | echo '<p>' . esc_html__( 'No integration addons are currently activated. Install and activate an integration addon to connect your forms with third-party services.', 'everest-forms' ) . '</p>'; |
| 151 | echo '<p style="margin-top: 24px;"><a class="everest-forms-btn everest-forms-btn-primary" href="' . esc_url( $addons_url ) . '">' . esc_html__( 'Go to Addons Page', 'everest-forms' ) . '</a></p>'; |
| 152 | echo '</div>'; |
| 153 | } else { |
| 154 | $upgrade_url = apply_filters( |
| 155 | 'everest_forms_upgrade_url', |
| 156 | 'https://everestforms.net/upgrade/?utm_medium=evf-form-builder&utm_source=evf-free&utm_campaign=builder-pro-field-popup&utm_content=Upgrade%20to%20Pro' |
| 157 | ); |
| 158 | echo '<div class="evf-panel-content-section evf-panel-content-section-info evf-builder-get-started">'; |
| 159 | echo '<h3>' . esc_html__( 'Get Started with Integrations', 'everest-forms-pro' ) . '</h3>'; |
| 160 | echo '<p>' . esc_html__( 'Integrations are available in the Pro plan. Upgrade to install and connect them.', 'everest-forms-pro' ) . '</p>'; |
| 161 | echo '<div class="evf-builder-get-started-steps" style="display: flex; gap: 20px;">'; |
| 162 | echo '<span class="step" style="display: flex; align-items: center; gap: 10px; width: fit-content;"><span style="width: 26px; height: 26px; display: inline-block; background-color: #E1E1E1; border-radius: 4px; text-align: center; line-height: 24px;">1</span>' . esc_html__( 'Upgrade', 'everest-forms-pro' ) . '</span>'; |
| 163 | echo '<span class="step" style="display: flex; align-items: center; gap: 10px; width: fit-content;"><span style="width: 26px; height: 26px; display: inline-block; background-color: #E1E1E1; border-radius: 4px; text-align: center; line-height: 24px;">2</span>' . esc_html__( 'Activate add-on', 'everest-forms-pro' ) . '</span>'; |
| 164 | echo '<span class="step" style="display: flex; align-items: center; gap: 10px; width: fit-content;"><span style="width: 26px; height: 26px; display: inline-block; background-color: #E1E1E1; border-radius: 4px; text-align: center; line-height: 24px;">3</span>' . esc_html__( 'Connect', 'everest-forms-pro' ) . '</span>'; |
| 165 | echo '</div>'; |
| 166 | echo '<p style="margin-top: 40px;"><a class="everest-forms-btn everest-forms-btn-primary" style="display:inline-flex;align-items:center;gap:8px;" target="_blank" rel="noopener noreferrer" href="' . esc_url( $upgrade_url ) . '">' . esc_html__( 'Upgrade Plan', 'everest-forms-pro' ) . '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14" width="14" height="14" aria-hidden="true" focusable="false"><path fill="#efefef" d="m7 1.167 3.5 9.333h-7z"/><path fill="#fff" fill-rule="evenodd" d="M12 12.834H2v-1.667h10zm0-2.334H2l-.833-7L7 8.312 12.833 3.5z" clip-rule="evenodd"/></svg></a></p>'; |
| 167 | echo '</div>'; |
| 168 | } |
| 169 | } else { |
| 170 | do_action( 'everest_forms_providers_panel_content', $this->form ); |
| 171 | wp_localize_script( |
| 172 | 'everest-forms-integrations-scripts', |
| 173 | 'evf_integration_data', |
| 174 | isset( $this->form_data['integrations'] ) ? $this->form_data['integrations'] : array() |
| 175 | ); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | return new EVF_Builder_Integrations(); |
| 181 | |
| 182 | } |
| 183 |