PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.3.7
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.3.7
7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / inc / class-hustle-admin-page-abstract.php
wordpress-popup / inc Last commit date
display-conditions 5 years ago front 5 years ago helpers 5 years ago metas 5 years ago palettes 5 years ago provider 5 years ago providers 5 years ago templates 5 years ago update 5 years ago class-hustle-admin-page-abstract.php 5 years ago class-hustle-condition-factory.php 6 years ago class-hustle-dashboard-admin.php 5 years ago class-hustle-data.php 5 years ago class-hustle-db.php 6 years ago class-hustle-module-admin.php 5 years ago class-hustle-module-collection.php 5 years ago class-hustle-module-decorator.php 5 years ago class-hustle-module-page-abstract.php 5 years ago class-hustle-notifications.php 5 years ago class-hustle-settings-admin.php 5 years ago class-hustle-upsell-page.php 5 years ago class-hustle-wp-dashboard-page.php 5 years ago hustle-collection.php 6 years ago hustle-deletion.php 5 years ago hustle-embedded-admin.php 6 years ago hustle-entries-admin.php 5 years ago hustle-entry-model.php 5 years ago hustle-general-data-protection.php 6 years ago hustle-init.php 5 years ago hustle-mail.php 5 years ago hustle-meta.php 5 years ago hustle-migration.php 5 years ago hustle-model.php 5 years ago hustle-module-model.php 5 years ago hustle-module-widget-legacy.php 5 years ago hustle-module-widget.php 5 years ago hustle-modules-common-admin-ajax.php 5 years ago hustle-popup-admin.php 6 years ago hustle-providers-admin.php 5 years ago hustle-providers.php 6 years ago hustle-settings-admin-ajax.php 5 years ago hustle-settings-page.php 5 years ago hustle-slidein-admin.php 6 years ago hustle-sshare-admin.php 5 years ago hustle-sshare-model.php 5 years ago hustle-tracking-model.php 5 years ago opt-in-geo.php 5 years ago opt-in-utils.php 5 years ago opt-in-wpmudev-api.php 6 years ago
class-hustle-admin-page-abstract.php
581 lines
1 <?php
2 /**
3 * File for Hustle_Admin_Page_Abstract class.
4 *
5 * @package Hustle
6 * @since 4.0.1
7 */
8
9 if ( ! class_exists( 'Hustle_Admin_Page_Abstract' ) ) :
10 /**
11 * Class Hustle_Admin_Page_Abstract.
12 * This is the base class for all Hustle's pages.
13 *
14 * @since 4.0.1
15 */
16 abstract class Hustle_Admin_Page_Abstract {
17
18 /**
19 * Page slug defined by us.
20 *
21 * @since 4.0.1
22 * @var string
23 */
24 protected $page;
25
26 /**
27 * Template path for the page relative to the 'views' folder.
28 *
29 * @since 4.0.1
30 * @var string
31 */
32 protected $page_template_path;
33
34 /**
35 * Page title.
36 *
37 * @since 4.0.1
38 * @var string
39 */
40 protected $page_title;
41
42 /**
43 * Page title for the WordPress menu.
44 *
45 * @since 4.0.1
46 * @var string
47 */
48 protected $page_menu_title;
49
50 /**
51 * Required capability for the page to be available.
52 *
53 * @since 4.0.1
54 * @var string
55 */
56 protected $page_capability;
57
58 /**
59 * The current page that's being requested.
60 *
61 * @since 4.0.2
62 * @var string|bool
63 */
64 protected $current_page;
65
66 /**
67 * Page slug defined by WordPress when registering the page.
68 *
69 * @since 4.0.0
70 * @var string
71 */
72 protected $page_slug;
73
74 /**
75 * Instance of Hustle_Layout_Helper
76 *
77 * @since 4.2.0
78 * @var Hustle_Layout_Helper
79 */
80 private $renderer;
81
82 /**
83 * Class constructor.
84 *
85 * @since 4.0.1
86 */
87 public function __construct() {
88
89 $this->current_page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
90
91 $this->init();
92
93 add_action( 'admin_menu', array( $this, 'register_admin_menu' ) );
94 }
95
96 /**
97 * Initiate the page's properties
98 * Should be overridden by each page.
99 *
100 * @since 4.0.1
101 */
102 abstract protected function init();
103
104 /**
105 * Register the admin menus.
106 *
107 * @since 4.0.1
108 */
109 public function register_admin_menu() {
110
111 $this->page_slug = add_submenu_page( 'hustle', $this->page_title, $this->page_menu_title, $this->page_capability, $this->page, array( $this, 'render_main_page' ) );
112
113 add_action( 'admin_init', array( $this, 'maybe_export' ) );
114 add_action( 'load-' . $this->page_slug, array( $this, 'current_page_loaded' ) );
115 }
116
117 /**
118 * Gets an instance of the renderer class.
119 *
120 * @since 4.2.1
121 * @return Hustle_Layout_Helper
122 */
123 protected function get_renderer() {
124 if ( ! $this->renderer ) {
125 $this->renderer = new Hustle_Layout_Helper( $this );
126 }
127 return $this->renderer;
128 }
129
130 /**
131 * Check if it's export - run the relevant action.
132 */
133 public function maybe_export() {
134 $this->export_module();
135 }
136
137 /**
138 * Render the main page
139 *
140 * @since 4.0.1
141 */
142 public function render_main_page() {
143 ?>
144 <div class="<?php echo esc_attr( $this->get_sui_wrap_class() ); ?>">
145
146 <?php
147 $template_args = $this->get_page_template_args();
148 $renderer = $this->get_renderer();
149 $renderer->render( $this->page_template_path, $template_args );
150
151 $this->render_modals();
152 ?>
153
154 </div>
155 <?php
156 }
157
158 /**
159 * Perform actions during the 'load-{page}' hook.
160 *
161 * @since 4.0.4
162 */
163 public function current_page_loaded() {
164 $this->maybe_export();
165 add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ), 99 );
166 add_action( 'admin_print_styles', array( $this, 'register_styles' ) );
167 add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ), 99 );
168 add_filter( 'removable_query_args', array( $this, 'remove_notice_params' ) );
169 }
170
171 /**
172 * Print forminator scripts for preview.
173 * Used by Dashboard, Wizards, and Listings.
174 *
175 * @since 4.0.1
176 */
177 public function maybe_print_forminator_scripts() {
178
179 // Add Forminator's front styles and scripts for preview.
180 if ( defined( 'FORMINATOR_VERSION' ) ) {
181 forminator_print_front_styles( FORMINATOR_VERSION );
182 forminator_print_front_scripts( FORMINATOR_VERSION );
183
184 }
185 }
186
187 /**
188 * Register scripts for the admin page.
189 *
190 * @since 4.3.1
191 *
192 * @param string $page_slug Page slug.
193 */
194 public function register_scripts( $page_slug ) {
195
196 wp_enqueue_script(
197 'shared-ui',
198 Opt_In::$plugin_url . 'assets/js/shared-ui.min.js',
199 array( 'jquery' ),
200 HUSTLE_SUI_VERSION,
201 true
202 );
203
204 /**
205 * Filters the variable to be localized into the js side of Hustle's admin pages.
206 *
207 * @since unknown
208 */
209 $optin_vars = apply_filters( 'hustle_optin_vars', $this->get_vars_to_localize() );
210
211 $url_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'debug' : 'min';
212 wp_register_script(
213 'optin_admin_scripts',
214 Opt_In::$plugin_url . 'assets/js/admin.' . $url_suffix . '.js',
215 array( 'jquery', 'backbone', 'jquery-effects-core' ),
216 Opt_In::VERSION,
217 true
218 );
219 wp_localize_script( 'optin_admin_scripts', 'optinVars', $optin_vars );
220 wp_enqueue_script( 'optin_admin_scripts' );
221 }
222
223 /**
224 * Register the js variables to be localized for this page.
225 *
226 * @since 4.3.1
227 *
228 * @return array
229 */
230 protected function get_vars_to_localize() {
231 return array(
232 'dismiss_notice_nonce' => wp_create_nonce( 'hustle_dismiss_notification' ),
233 'urlParams' => $_GET, // phpcs:ignore WordPress.Security.NonceVerification.Recommended
234 'module_page' => array(
235 'popup' => Hustle_Data::POPUP_LISTING_PAGE,
236 'slidein' => Hustle_Data::SLIDEIN_LISTING_PAGE,
237 'embedded' => Hustle_Data::EMBEDDED_LISTING_PAGE,
238 'social_sharing' => Hustle_Data::SOCIAL_SHARING_LISTING_PAGE,
239 ),
240 'messages' => array(
241 'something_went_wrong' => __( 'Something went wrong. Please try again', 'hustle' ), // everywhere.
242 'something_went_wrong_reload' => '<label class="wpmudev-label--notice"><span>' . __( 'Something went wrong. Please reload this page and try again.', 'hustle' ) . '</span></label>', // everywhere.
243 /* translators: "Aweber" between "strong" tags */
244 'aweber_migration_success' => sprintf( esc_html__( '%s integration successfully migrated to the oAuth 2.0.', 'hustle' ), '<strong>' . esc_html__( 'Aweber', 'hustle' ) . '</strong>' ), // everywhere. views.js.
245 'integraiton_required' => '<label class="wpmudev-label--notice"><span>' . __( 'An integration is required on opt-in module.', 'hustle' ) . '</span></label>', // wizard and integrations.
246 'module_deleted' => __( 'Module successfully deleted.', 'hustle' ), // listing and dashboard.
247 'shortcode_copied' => __( 'Shortcode copied successfully.', 'hustle' ), // listing and dashboard.
248 'commons' => array(
249 'published' => __( 'Published', 'hustle' ), // dashboard and wizard.
250 'draft' => __( 'Draft', 'hustle' ), // dashboard and wizard.
251 'dismiss' => __( 'Dismiss', 'hustle' ), // everywhere, views.js.
252 ),
253 'request_error_reload_notice' => __( 'There was an issue processing your request. Please reload the page and try again.', 'hustle' ),
254 ),
255 );
256 }
257
258 /**
259 * Registers styles for the admin pages.
260 *
261 * @since 4.3.1
262 *
263 * @param string $page_slug Slug of the current page.
264 */
265 public function register_styles( $page_slug ) {
266 wp_enqueue_style( 'thickbox' );
267
268 wp_register_style(
269 'hstl-roboto',
270 'https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:300,300i,400,400i,500,500i,700,700i',
271 array(),
272 Opt_In::VERSION
273 );
274 wp_register_style(
275 'hstl-opensans',
276 'https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i',
277 array(),
278 Opt_In::VERSION
279 );
280 wp_register_style(
281 'hstl-source',
282 'https://fonts.googleapis.com/css?family=Source+Code+Pro',
283 array(),
284 Opt_In::VERSION
285 );
286
287 wp_enqueue_style( 'wp-color-picker' );
288 wp_enqueue_style( 'wdev_ui' );
289 wp_enqueue_style( 'wdev_notice' );
290 wp_enqueue_style( 'hstl-roboto' );
291 wp_enqueue_style( 'hstl-opensans' );
292 wp_enqueue_style( 'hstl-source' );
293
294 wp_enqueue_style(
295 'sui_styles',
296 Opt_In::$plugin_url . 'assets/css/shared-ui.min.css',
297 array(),
298 HUSTLE_SUI_VERSION
299 );
300 }
301
302 /**
303 * Adds a class to the page body with the SUI version.
304 *
305 * @since 4.3.1
306 *
307 * @param string $classes Current set of classes to be added.
308 * @return string
309 */
310 public function add_admin_body_class( $classes ) {
311 $formatted_version = str_replace( '.', '-', HUSTLE_SUI_VERSION );
312
313 $classes .= ' sui-' . $formatted_version;
314
315 return $classes;
316 }
317
318 /**
319 * Remove Get parameters for Hustle notices
320 *
321 * @since 4.3.1
322 *
323 * @param string[] $vars An array of query variables to remove from a URL.
324 * @return array
325 */
326 public function remove_notice_params( $vars ) {
327 $vars[] = 'show-notice';
328 $vars[] = 'notice';
329 $vars[] = 'notice-close';
330
331 return $vars;
332 }
333
334 /**
335 * Exports a single module.
336 * Used by Dashboard and Listing.
337 *
338 * @since 4.0.0
339 * @since 4.2.0 Moved from Hustle_Modules_Common_Admin to this class.
340 */
341 protected function export_module() {
342
343 $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
344 if ( ! wp_verify_nonce( $nonce, 'hustle_module_export' ) ) {
345 return;
346 }
347 $id = filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT );
348 if ( ! $id ) {
349 return;
350 }
351 // Plugin data.
352 $plugin = get_plugin_data( WP_PLUGIN_DIR . '/' . Opt_In::$plugin_base_file );
353
354 // Get module.
355 $module = new Hustle_Module_Model( $id );
356 if ( is_wp_error( $module ) ) {
357 return;
358 }
359
360 // Export data.
361 $settings = array(
362 'plugin' => array(
363 'name' => $plugin['Name'],
364 'version' => Opt_In::VERSION,
365 'network' => $plugin['Network'],
366 ),
367 'timestamp' => time(),
368 'attributes' => $module->get_attributes(),
369 'data' => $module->get_data(),
370 'meta' => array(),
371 );
372
373 if ( 'optin' === $module->module_mode ) {
374 $integrations = array();
375 $providers = Hustle_Providers::get_instance()->get_providers();
376 foreach ( $providers as $slug => $provider ) {
377 $provider_data = $module->get_provider_settings( $slug, false );
378 if ( $provider_data && $provider->is_connected()
379 && $provider->is_form_connected( $id ) ) {
380 $integrations[ $slug ] = $provider_data;
381 }
382 }
383
384 $settings['meta']['integrations'] = $integrations;
385 }
386
387 $meta_names = $module->get_module_meta_names();
388 foreach ( $meta_names as $meta_key ) {
389 $settings['meta'][ $meta_key ] = json_decode( $module->get_meta( $meta_key ) );
390 }
391 /**
392 * Filename
393 */
394 $filename = sprintf(
395 'hustle-%s-%s-%s-%s.json',
396 $module->module_type,
397 gmdate( 'Ymd-his' ),
398 get_bloginfo( 'name' ),
399 $module->module_name
400 );
401 $filename = strtolower( $filename );
402 $filename = sanitize_file_name( $filename );
403 /**
404 * Print HTTP headers
405 */
406 header( 'Content-Description: File Transfer' );
407 header( 'Content-Disposition: attachment; filename=' . $filename );
408 header( 'Content-Type: application/bin; charset=' . get_option( 'blog_charset' ), true );
409 /**
410 * Check PHP version, for PHP < 3 do not add options
411 */
412 $version = phpversion();
413 $compare = version_compare( $version, '5.3', '<' );
414 if ( $compare ) {
415 echo wp_json_encode( $settings );
416 exit;
417 }
418 $option = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
419 echo wp_json_encode( $settings, $option );
420 exit;
421 }
422
423 /**
424 * Filter related to TinyMCE
425 * Used by Settings and Wizard pages.
426 *
427 * @since 4.2.0 Moved from Hustle_Module_Admin to this class.
428 */
429 protected function set_up_tinymce() {
430
431 add_filter( 'tiny_mce_before_init', array( $this, 'set_tinymce_settings' ), 10, 2 );
432 add_filter( 'wp_default_editor', array( $this, 'set_editor_to_tinymce' ) );
433 add_filter( 'tiny_mce_plugins', array( $this, 'remove_despised_editor_plugins' ) );
434 }
435
436 /**
437 * Modify tinymce editor settings.
438 *
439 * @param array $settings Registered settings.
440 * @param string $editor_id Current editor ID.
441 */
442 public function set_tinymce_settings( $settings, $editor_id ) {
443 $settings['paste_as_text'] = 'true';
444
445 return $settings;
446 }
447
448 /**
449 * Sets default editor to tinymce for opt-in admin
450 *
451 * @param string $editor_type Current editor type.
452 * @return string
453 */
454 public function set_editor_to_tinymce( $editor_type ) {
455 return 'tinymce';
456 }
457
458 /**
459 * Removes unnecessary editor plugins
460 *
461 * @param array $plugins Registered plugins.
462 * @return mixed
463 */
464 public function remove_despised_editor_plugins( $plugins ) {
465 $k = array_search( 'fullscreen', $plugins, true );
466 if ( false !== $k ) {
467 unset( $plugins[ $k ] );
468 }
469 $plugins[] = 'paste';
470 return $plugins;
471 }
472
473 /**
474 * Gets the current tab the page is on load.
475 * Used by wizards and the global settings page.
476 *
477 * @since 4.3.1
478 *
479 * @param boolean|string $default Default value.
480 * @return boolean|string
481 */
482 protected function get_current_section( $default = false ) {
483 $section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_STRING );
484 return empty( $section ) ? $default : $section;
485 }
486
487 /**
488 * SUI summary config.
489 *
490 * @since 4.2.0
491 *
492 * @param string|null $class Class to be added.
493 */
494 protected function get_sui_summary_config( $class = null ) {
495 $style = '';
496 $image_url = apply_filters( 'wpmudev_branding_hero_image', null );
497 if ( ! empty( $image_url ) ) {
498 $style = 'background-image:url(' . esc_url( $image_url ) . ')';
499 }
500 $sui = array(
501 'summary' => array(
502 'style' => $style,
503 'classes' => array(
504 'sui-box',
505 'sui-summary',
506 ),
507 ),
508 );
509 if ( ! empty( $class ) && is_string( $class ) ) {
510 $sui['summary']['classes'][] = $class;
511 }
512 /**
513 * Dash integration
514 *
515 * @since 4.0.0
516 */
517 $hide_branding = apply_filters( 'wpmudev_branding_hide_branding', false );
518 $branding_image = apply_filters( 'wpmudev_branding_hero_image', null );
519 if ( $hide_branding && ! empty( $branding_image ) ) {
520 $sui['summary']['classes'][] = 'sui-rebranded';
521 } elseif ( $hide_branding && empty( $branding_image ) ) {
522 $sui['summary']['classes'][] = 'sui-unbranded';
523 }
524 return $sui;
525 }
526
527 /**
528 * Gets the SUI classes according to the selected setitngs in WPMU Dev dashboard.
529 *
530 * @since 4.3.1
531 *
532 * @return string
533 */
534 protected function get_sui_wrap_class() {
535 $classes = array( 'sui-wrap', 'sui-wrap-hustle' );
536
537 /**
538 * Add high contrast mode.
539 */
540 $accessibility = Hustle_Settings_Admin::get_hustle_settings( 'accessibility' );
541 $is_high_contrast_mode = ! empty( $accessibility['accessibility_color'] );
542 if ( $is_high_contrast_mode ) {
543 $classes[] = 'sui-color-accessible';
544 }
545
546 /**
547 * Set hide branding.
548 *
549 * @since 4.0.0
550 */
551 $hide_branding = apply_filters( 'wpmudev_branding_hide_branding', false );
552 if ( $hide_branding ) {
553 $classes[] = 'no-hustle';
554 }
555 /**
556 * Hero image.
557 *
558 * @since 4.0.0
559 */
560 $image = apply_filters( 'wpmudev_branding_hero_image', 'hustle-default' );
561 if ( empty( $image ) ) {
562 $classes[] = 'no-hustle-hero';
563 }
564
565 $classes = apply_filters( 'hustle_sui_wrap_class', $classes );
566
567 return implode( ' ', $classes );
568 }
569
570 /**
571 * Renders the modals.
572 * This abstract class renders the modals that are displayed on all hustle's pages.
573 * Each page should override this method to add the specific modals for it.
574 *
575 * @since 4.3.5
576 */
577 protected function render_modals() {}
578 }
579
580 endif;
581