PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.0.7
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.0.7
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / admin / class-leadinadmin.php

class-leadinadmin.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.0.7, at public/admin/class-leadinadmin.php

285 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\admin;
4
5 use Leadin\AssetsManager;
6 use Leadin\data\User;
7 use Leadin\admin\Connection;
8 use Leadin\data\User_Metadata;
9 use Leadin\admin\MenuConstants;
10 use Leadin\admin\Gutenberg;
11 use Leadin\admin\NoticeManager;
12 use Leadin\admin\PluginActionsManager;
13 use Leadin\admin\DeactivationForm;
14 use Leadin\admin\Links;
15 use Leadin\auth\OAuth;
16 use Leadin\admin\utils\Background;
17 use Leadin\utils\QueryParameters;
18 use Leadin\utils\Versions;
19 use Leadin\includes\utils as utils;
20
21 use Leadin\data\Portal_Options;
22 use Leadin\data\Filters;
23
24 /**
25 * Class responsible for initializing the admin side of the plugin.
26 */
27 class LeadinAdmin {
28 const REDIRECT_TRANSIENT = 'leadin_redirect_after_activation';
29
30 /**
31 * Class constructor, adds all the hooks and instantiate the APIs.
32 */
33 public function __construct() {
34 add_action( 'plugins_loaded', array( $this, 'load_languages' ), 14 );
35 add_action( 'admin_init', array( $this, 'redirect_after_activation' ) );
36 add_action( 'admin_init', array( $this, 'store_activation_time' ) );
37 add_action( 'admin_init', array( $this, 'authorize' ) );
38 add_action( 'admin_init', array( $this, 'check_review_requested' ) );
39 add_action( 'admin_menu', array( $this, 'build_menu' ) );
40 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
41 register_activation_hook( LEADIN_BASE_PATH, array( $this, 'do_activate_action' ) );
42
43 /**
44 * The following hooks are public APIs.
45 */
46 add_action( 'leadin_redirect', array( $this, 'set_redirect_transient' ) );
47 add_action( 'leadin_activate', array( $this, 'do_redirect_action' ), 100 );
48
49 new PluginActionsManager();
50 new DeactivationForm();
51 new NoticeManager();
52 new Gutenberg();
53 add_action( 'elementor/documents/register_controls', array( $this, 'register_document_controls' ) );
54 }
55
56 /**
57 * Register additional document controls.
58 *
59 * @param \Elementor\Core\DocumentTypes\PageBase $document The PageBase document instance.
60 */
61 public function register_document_controls( $document ) {
62 if ( ! $document instanceof \Elementor\Core\DocumentTypes\PageBase || ! $document::get_property( 'has_elements' ) ) {
63 return;
64 }
65
66 $document->start_controls_section(
67 'hubspot',
68 array(
69 'label' => esc_html__( 'Hubspot', 'leadin' ),
70 'tab' => \Elementor\Controls_Manager::TAB_SETTINGS,
71 )
72 );
73
74 $document->add_control(
75 'content_type',
76 array(
77 'label' => esc_html__( 'Select the content type HubSpot Analytics uses to track this page.', 'leadin' ),
78 'label_block' => true,
79 'type' => \Elementor\Controls_Manager::SELECT,
80 'options' => array(
81 '' => esc_html__( 'Detect Automatically', 'leadin' ),
82 'blog-post' => esc_html__( 'Blog Post', 'leadin' ),
83 'knowledge-article' => esc_html__( 'Knowledge Article', 'leadin' ),
84 'landing-page' => esc_html__( 'Landing Page', 'leadin' ),
85 'listing-page' => esc_html__( 'Listing Page', 'leadin' ),
86 'standard-page' => esc_html__( 'Standard Page', 'leadin' ),
87 ),
88 'default' => '',
89 )
90 );
91
92 $document->end_controls_section();
93 }
94
95
96
97 /**
98 * Load the .mo language files.
99 */
100 public function load_languages() {
101 load_plugin_textdomain( 'leadin', false, '/leadin/languages' );
102 }
103
104 /**
105 * Handler called on plugin activation.
106 */
107 public function do_activate_action() {
108 \do_action( 'leadin_activate' );
109 }
110
111 /**
112 * Handler for the leadin_activate action.
113 */
114 public function do_redirect_action() {
115 \do_action( 'leadin_redirect' );
116 }
117
118 /**
119 * Set transient after activating the plugin.
120 */
121 public function set_redirect_transient() {
122 set_transient( self::REDIRECT_TRANSIENT, true, 60 );
123 }
124
125 /**
126 * Redirect to the dashboard after activation.
127 */
128 public function redirect_after_activation() {
129 if ( get_transient( self::REDIRECT_TRANSIENT ) ) {
130 delete_transient( self::REDIRECT_TRANSIENT );
131 wp_safe_redirect( admin_url( 'admin.php?page=leadin' ) );
132 exit;
133 }
134 }
135
136 /**
137 * Connect/disconnect the plugin
138 */
139 public function authorize() {
140 if ( User::is_admin() ) {
141 if ( Connection::is_connection_requested() ) {
142 $redirect_params = array();
143 if ( ! Connection::is_connected() || Connection::is_same_portal() ) {
144 Connection::oauth_connect();
145 $redirect_params['leadin_just_connected'] = 1;
146 if ( Connection::is_new_portal() ) {
147 $redirect_params['is_new_portal'] = 1;
148 }
149 }
150 Routing::redirect( MenuConstants::USER_GUIDE, $redirect_params );
151 } elseif ( Connection::is_disconnection_requested() ) {
152 Connection::disconnect();
153 Routing::redirect( MenuConstants::ROOT );
154 }
155 }
156 }
157
158 /**
159 * Check if query parameter for review is present on the request
160 * then add user metadata to persist review time
161 * Redirects if value is equal to true
162 */
163 public function check_review_requested() {
164 if ( Connection::is_connected() && Routing::has_review_request() ) {
165 User_Metadata::set_skip_review( time() );
166 if ( Routing::is_review_request() ) {
167 header( 'Location: https://survey.hsforms.com/1ILAEu_k_Ttiy344dpHM--w1h' );
168 exit();
169 }
170 }
171 }
172
173 /**
174 * Store activation time in a WP option.
175 */
176 public function store_activation_time() {
177 if ( empty( Portal_Options::get_activation_time() ) ) {
178 Portal_Options::set_activation_time();
179 }
180 }
181
182 /**
183 * Adds scripts for the admin section.
184 */
185 public function enqueue_scripts() {
186 AssetsManager::register_assets();
187 AssetsManager::enqueue_admin_assets();
188 if ( get_current_screen()->id === 'plugins' ) {
189 AssetsManager::enqueue_feedback_assets();
190 }
191 }
192
193 /**
194 * Adds Leadin menu to admin sidebar
195 */
196 public function build_menu() {
197 if ( Connection::is_connected() ) {
198 add_menu_page( __( 'HubSpot', 'leadin' ), __( 'HubSpot', 'leadin' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::ROOT, array( $this, 'build_integrated_app' ), 'dashicons-sprocket', '25.100713' );
199
200 add_submenu_page( MenuConstants::ROOT, __( 'User Guide', 'leadin' ), __( 'User Guide', 'leadin' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::USER_GUIDE, array( $this, 'build_integrated_app' ) );
201 add_submenu_page( MenuConstants::ROOT, __( 'Forms', 'leadin' ), __( 'Forms', 'leadin' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::FORMS, array( $this, 'build_integrated_app' ) );
202 add_submenu_page( MenuConstants::ROOT, __( 'Live Chat', 'leadin' ), __( 'Live Chat', 'leadin' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::CHATFLOWS, array( $this, 'build_integrated_app' ) );
203
204 add_submenu_page( MenuConstants::ROOT, __( 'Contacts', 'leadin' ), self::make_external_link( Links::get_iframe_src( MenuConstants::CONTACTS ), __( 'Contacts', 'leadin' ), 'leadin_contacts_link' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::CONTACTS, array( $this, 'build_app' ) );
205 add_submenu_page( MenuConstants::ROOT, __( 'Email', 'leadin' ), self::make_external_link( Links::get_iframe_src( MenuConstants::EMAIL ), __( 'Email', 'leadin' ), 'leadin_email_link' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::EMAIL, array( $this, 'build_app' ) );
206 add_submenu_page( MenuConstants::ROOT, __( 'Lists', 'leadin' ), self::make_external_link( Links::get_iframe_src( MenuConstants::LISTS ), __( 'Lists', 'leadin' ), 'leadin_lists_link' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::LISTS, array( $this, 'build_app' ) );
207 add_submenu_page( MenuConstants::ROOT, __( 'Reporting', 'leadin' ), self::make_external_link( Links::get_iframe_src( MenuConstants::REPORTING ), __( 'Reporting', 'leadin' ), 'leadin_reporting_link' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::REPORTING, array( $this, 'build_app' ) );
208
209 add_submenu_page( MenuConstants::ROOT, __( 'Settings', 'leadin' ), __( 'Settings', 'leadin' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::SETTINGS, array( $this, 'build_integrated_app' ) );
210
211 add_submenu_page( MenuConstants::ROOT, __( 'Upgrade', 'leadin' ), self::make_external_link( Links::get_iframe_src( MenuConstants::PRICING ), __( 'Upgrade', 'leadin' ), 'leadin_pricing_link' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::PRICING, array( $this, 'build_app' ) );
212
213 remove_submenu_page( MenuConstants::ROOT, MenuConstants::ROOT );
214 } else {
215 $notification_icon = ' <span class="update-plugins count-1"><span class="plugin-count">!</span></span>';
216 add_menu_page( __( 'HubSpot', 'leadin' ), __( 'HubSpot', 'leadin' ) . $notification_icon, Filters::apply_connect_plugin_capability_filters(), MenuConstants::ROOT, array( $this, 'build_integrated_app' ), 'dashicons-sprocket', '25.100713' );
217 }
218 }
219
220
221 /**
222 * Wraps external link.
223 *
224 * @param String $href link destination.
225 * @param String $content link content.
226 * @param String $class class for ATs.
227 */
228 public function make_external_link( $href, $content, $class ) {
229 return "<a href=\"$href\" class=\"external_link $class\" target=\"_blank\" onclick=\"blur()\">$content</a>";
230 }
231
232 /**
233 * Renders the leadin admin page.
234 */
235 public function build_app() {
236 AssetsManager::enqueue_bridge_assets();
237 self::render_app();
238 }
239
240 /**
241 * Renders the integrated forms app.
242 */
243 public function build_integrated_app() {
244 AssetsManager::enqueue_integrated_app_assets();
245 self::render_app();
246 }
247
248 /**
249 * Render app container
250 */
251 public function render_app() {
252 $error_message = '';
253
254 if ( Versions::is_php_version_not_supported() ) {
255 $error_message = sprintf(
256 __( 'HubSpot All-In-One Marketing %1$s requires PHP %2$s or higher. Please upgrade WordPress first.', 'leadin' ),
257 LEADIN_PLUGIN_VERSION,
258 LEADIN_REQUIRED_PHP_VERSION
259 );
260 } elseif ( Versions::is_wp_version_not_supported() ) {
261 $error_message = sprintf(
262 __( 'HubSpot All-In-One Marketing %1$s requires PHP %2$s or higher. Please upgrade WordPress first.', 'leadin' ),
263 LEADIN_PLUGIN_VERSION,
264 LEADIN_REQUIRED_WP_VERSION
265 );
266 }
267
268 if ( $error_message ) {
269 ?>
270 <div class='notice notice-warning'>
271 <p>
272 <?php echo esc_html( $error_message ); ?>
273 </p>
274 </div>
275 <?php
276 } else {
277 ?>
278 <div id="leadin-iframe-fallback-container"></div>
279 <div id="leadin-iframe-container"></div>
280 <?php
281 }
282 }
283
284 }
285