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

292 lines 10.5 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 * Note: As of WordPress 4.6+, translations are automatically loaded from WordPress.org
103 * for plugins hosted there, so load_plugin_textdomain() is no longer needed.
104 */
105 public function load_languages() {
106 // WordPress automatically loads translations for WordPress.org hosted plugins.
107 // This function is kept for backwards compatibility with the hook.
108 }
109
110 /**
111 * Handler called on plugin activation.
112 */
113 public function do_activate_action() {
114 \do_action( 'leadin_activate' );
115 }
116
117 /**
118 * Handler for the leadin_activate action.
119 */
120 public function do_redirect_action() {
121 \do_action( 'leadin_redirect' );
122 }
123
124 /**
125 * Set transient after activating the plugin.
126 */
127 public function set_redirect_transient() {
128 set_transient( self::REDIRECT_TRANSIENT, true, 60 );
129 }
130
131 /**
132 * Redirect to the dashboard after activation.
133 */
134 public function redirect_after_activation() {
135 if ( get_transient( self::REDIRECT_TRANSIENT ) ) {
136 delete_transient( self::REDIRECT_TRANSIENT );
137 wp_safe_redirect( admin_url( 'admin.php?page=leadin' ) );
138 exit;
139 }
140 }
141
142 /**
143 * Connect/disconnect the plugin
144 */
145 public function authorize() {
146 if ( User::is_admin() ) {
147 if ( Connection::is_connection_requested() ) {
148 $redirect_params = array();
149 Connection::oauth_connect();
150 $redirect_params['leadin_just_connected'] = 1;
151
152 if ( Connection::is_new_portal() ) {
153 $redirect_params['is_new_portal'] = 1;
154 }
155 Routing::redirect( MenuConstants::USER_GUIDE, $redirect_params );
156 } elseif ( Connection::is_disconnection_requested() ) {
157 Connection::disconnect();
158 Routing::redirect( MenuConstants::ROOT );
159 }
160 }
161 }
162
163 /**
164 * Check if query parameter for review is present on the request
165 * then add user metadata to persist review time
166 * Redirects if value is equal to true
167 */
168 public function check_review_requested() {
169 if ( Connection::is_connected() && Routing::has_review_request() ) {
170 User_Metadata::set_skip_review( time() );
171 if ( Routing::is_review_request() ) {
172 header( 'Location: https://survey.hsforms.com/1ILAEu_k_Ttiy344dpHM--w1h' );
173 exit();
174 }
175 }
176 }
177
178 /**
179 * Store activation time in a WP option.
180 */
181 public function store_activation_time() {
182 if ( empty( Portal_Options::get_activation_time() ) ) {
183 Portal_Options::set_activation_time();
184 }
185 }
186
187 /**
188 * Adds scripts for the admin section.
189 */
190 public function enqueue_scripts() {
191 AssetsManager::register_assets();
192 AssetsManager::enqueue_admin_assets();
193 if ( get_current_screen()->id === 'plugins' ) {
194 AssetsManager::enqueue_feedback_assets();
195 }
196 }
197
198 /**
199 * Adds Leadin menu to admin sidebar
200 */
201 public function build_menu() {
202 if ( Connection::is_connected() ) {
203 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' );
204
205 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' ) );
206 add_submenu_page( MenuConstants::ROOT, __( 'Forms', 'leadin' ), __( 'Forms', 'leadin' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::FORMS, array( $this, 'build_integrated_app' ) );
207 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' ) );
208
209 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' ) );
210 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' ) );
211 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' ) );
212 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' ) );
213
214 add_submenu_page( MenuConstants::ROOT, __( 'Settings', 'leadin' ), __( 'Settings', 'leadin' ), Filters::apply_view_plugin_menu_capability_filters(), MenuConstants::SETTINGS, array( $this, 'build_integrated_app' ) );
215
216 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' ) );
217
218 remove_submenu_page( MenuConstants::ROOT, MenuConstants::ROOT );
219 } else {
220 $notification_icon = ' <span class="update-plugins count-1"><span class="plugin-count">!</span></span>';
221 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' );
222 }
223 }
224
225
226 /**
227 * Wraps external link.
228 *
229 * @param String $href link destination.
230 * @param String $content link content.
231 * @param String $class class for ATs.
232 */
233 public function make_external_link( $href, $content, $class ) {
234 return "<a href=\"$href\" class=\"external_link $class\" target=\"_blank\" onclick=\"blur()\">$content</a>";
235 }
236
237 /**
238 * Renders the leadin admin page.
239 */
240 public function build_app() {
241 AssetsManager::enqueue_bridge_assets();
242 self::render_app();
243 }
244
245 /**
246 * Renders the integrated forms app.
247 */
248 public function build_integrated_app() {
249 AssetsManager::enqueue_integrated_app_assets();
250 self::render_app();
251 }
252
253 /**
254 * Render app container
255 */
256 public function render_app() {
257 $error_message = '';
258
259 if ( Versions::is_php_version_not_supported() ) {
260 $error_message = sprintf(
261 /* translators: %1$s: Plugin current version %2$s: PHP required version */
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_PHP_VERSION
265 );
266 } elseif ( Versions::is_wp_version_not_supported() ) {
267 $error_message = sprintf(
268 /* translators: %1$s: Plugin current version %2$s: WordPress required version */
269 __( 'HubSpot All-In-One Marketing %1$s requires WordPress %2$s or higher Please upgrade WordPress first', 'leadin' ),
270 LEADIN_PLUGIN_VERSION,
271 LEADIN_REQUIRED_WP_VERSION
272 );
273 }
274
275 if ( $error_message ) {
276 ?>
277 <div class='notice notice-warning'>
278 <p>
279 <?php echo esc_html( $error_message ); ?>
280 </p>
281 </div>
282 <?php
283 } else {
284 ?>
285 <div id="leadin-iframe-fallback-container"></div>
286 <div id="leadin-iframe-container"></div>
287 <?php
288 }
289 }
290
291 }
292