| 1 |
<?php |
| 2 |
namespace Leadin\admin\widgets; |
| 3 |
|
| 4 |
use Leadin\data\Filters; |
| 5 |
use Leadin\data\Portal_Options; |
| 6 |
use Leadin\utils\ShortcodeRenderUtils; |
| 7 |
use Elementor\Plugin; |
| 8 |
use Elementor\Widget_Base; |
| 9 |
|
| 10 |
/** |
| 11 |
* ElementorForm Widget |
| 12 |
*/ |
| 13 |
class ElementorForm extends Widget_Base { |
| 14 |
|
| 15 |
/** |
| 16 |
* Widget internal name. |
| 17 |
*/ |
| 18 |
public function get_name() { |
| 19 |
return 'hubspot-form'; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Widget title. |
| 24 |
*/ |
| 25 |
public function get_title() { |
| 26 |
return esc_html( 'HubSpot Form' ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Widget display icon. |
| 31 |
*/ |
| 32 |
public function get_icon() { |
| 33 |
return 'eicon-form-horizontal'; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Widget help url. |
| 38 |
*/ |
| 39 |
public function get_custom_help_url() { |
| 40 |
return 'https://wordpress.org/support/plugin/leadin/'; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Widget category. |
| 45 |
*/ |
| 46 |
public function get_categories() { |
| 47 |
return array( 'general', 'hubspot' ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Widget keywords. |
| 52 |
*/ |
| 53 |
public function get_keywords() { |
| 54 |
return array( 'hubspot', 'form', 'leadin' ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Widget style. |
| 59 |
*/ |
| 60 |
public function get_style_depends() { |
| 61 |
wp_register_style( 'leadin-elementor', LEADIN_JS_BASE_PATH . '/elementor.css', array(), LEADIN_PLUGIN_VERSION ); |
| 62 |
wp_register_style( 'leadin-css', LEADIN_ASSETS_PATH . '/style/leadin.css', array(), LEADIN_PLUGIN_VERSION ); |
| 63 |
return array( 'leadin-elementor', 'leadin-css' ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Widget script. |
| 68 |
*/ |
| 69 |
public function get_script_depends() { |
| 70 |
wp_register_script( |
| 71 |
'leadin-forms-v2', |
| 72 |
Filters::apply_forms_script_url_filters(), |
| 73 |
array(), |
| 74 |
LEADIN_PLUGIN_VERSION, |
| 75 |
true |
| 76 |
); |
| 77 |
|
| 78 |
$scopes = array( 'leadin-forms-v2' ); |
| 79 |
$portal_id = Portal_Options::get_portal_id(); |
| 80 |
if ( $portal_id ) { |
| 81 |
wp_register_script( |
| 82 |
'leadin-forms-v4', |
| 83 |
Filters::apply_forms_v4_script_url_filters( $portal_id ), |
| 84 |
array(), |
| 85 |
LEADIN_PLUGIN_VERSION, |
| 86 |
true |
| 87 |
); |
| 88 |
$scopes[] = 'leadin-forms-v4'; |
| 89 |
} |
| 90 |
return $scopes; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Widget controls. |
| 95 |
*/ |
| 96 |
protected function register_controls() { |
| 97 |
$this->start_controls_section( |
| 98 |
'content_section', |
| 99 |
array( |
| 100 |
'label' => esc_html( __( 'Form', 'leadin' ) ), |
| 101 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 102 |
) |
| 103 |
); |
| 104 |
|
| 105 |
$this->add_control( |
| 106 |
'content', |
| 107 |
array( |
| 108 |
'type' => 'leadinformselect', |
| 109 |
) |
| 110 |
); |
| 111 |
|
| 112 |
$this->end_controls_section(); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Render the widget |
| 117 |
*/ |
| 118 |
protected function render() { |
| 119 |
$settings = $this->get_settings_for_display(); |
| 120 |
$content = $settings['content']; |
| 121 |
$is_edit_mode = Plugin::$instance->editor->is_edit_mode(); |
| 122 |
|
| 123 |
if ( $is_edit_mode ) { |
| 124 |
|
| 125 |
?> |
| 126 |
<div class="hubspot-form-edit-mode" data-attributes="<?php echo esc_attr( wp_json_encode( $content ) ); ?>"> |
| 127 |
|
| 128 |
</div> |
| 129 |
<?php |
| 130 |
if ( empty( $content ) ) { |
| 131 |
?> |
| 132 |
<div class="hubspot-widget-empty"> |
| 133 |
|
| 134 |
</div> |
| 135 |
<?php |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if ( ! empty( $content ) ) { |
| 140 |
$portal_id = $content['portalId']; |
| 141 |
$form_id = $content['formId']; |
| 142 |
$version = isset( $content['embedVersion'] ) ? $content['embedVersion'] : ''; |
| 143 |
$embed = do_shortcode( '[hubspot portal="' . $portal_id . '" id="' . $form_id . '" type="form" version="' . $version . '"]' ); |
| 144 |
|
| 145 |
if ( $is_edit_mode ) { |
| 146 |
$embed = ShortcodeRenderUtils::wrap_embed_for_elementor_editor( $embed ); |
| 147 |
} |
| 148 |
|
| 149 |
echo $embed; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- shortcode output. |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|