PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.0.54
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.0.54
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.54, at public/admin/class-leadinadmin.php

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