Completed
Push — master ( 0691eb...d055d1 )
by Stephanie
03:44 queued 01:07
created

FrmInboxController::inbox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * @since 4.05
4
 */
5
class FrmInboxController {
6
7
	/**
8
	 * @since 4.05
9
	 */
10
	public static function menu() {
11
		$unread = self::get_notice_count();
12
13
		add_submenu_page( 'formidable', 'Formidable | ' . __( 'Inbox', 'formidable' ), __( 'Inbox', 'formidable' ) . $unread, 'frm_change_settings', 'formidable-inbox', 'FrmInboxController::inbox' );
14
	}
15
16
	/**
17
	 * @since 4.05
18
	 */
19
	private static function get_notice_count() {
20
		FrmFormMigratorsHelper::maybe_add_to_inbox();
21
22
		$inbox  = new FrmInbox();
23
		return $inbox->unread_html();
24
	}
25
26
	/**
27
	 * @since 4.06
28
	 */
29
	public static function dismiss_all_button( $atts ) {
30
		$user_id      = get_current_user_id();
31
		$has_messages = false;
32
		foreach ( $atts['messages'] as $key => $message ) {
33
			if ( isset( $message['dismissed'] ) && isset( $message['dismissed'][ $user_id ] ) ) {
34
				continue;
35
			}
36
			$has_messages = true;
37
			break;
38
		}
39
		if ( ! $has_messages ) {
40
			return;
41
		}
42
43
		echo '<button class="button-secondary frm-button-secondary" id="frm-dismiss-inbox" type="button">' .
44
			esc_html__( 'Dismiss All', 'formidable' ) .
45
			'</button>';
46
	}
47
48
	/**
49
	 * @since 4.05
50
	 */
51
	public static function inbox() {
52
		FrmAppHelper::include_svg();
53
		self::add_tracking_request();
54
55
		$inbox    = new FrmInbox();
56
		$messages = $inbox->get_messages();
57
		$messages = array_reverse( $messages );
58
		$user     = wp_get_current_user();
59
60
		include( FrmAppHelper::plugin_path() . '/classes/views/inbox/list.php' );
61
	}
62
63
	/**
64
	 * @since 4.05
65
	 */
66
	public static function dismiss_message() {
67
		check_ajax_referer( 'frm_ajax', 'nonce' );
68
		FrmAppHelper::permission_check( 'frm_change_settings' );
69
70
		$key = FrmAppHelper::get_param( 'key', '', 'post', 'sanitize_text_field' );
71
		if ( ! empty( $key ) ) {
72
			$message = new FrmInbox();
73
			$message->dismiss( $key );
74
			if ( $key === 'review' ) {
75
				$reviews = new FrmReviews();
76
				$reviews->dismiss_review();
77
			}
78
		}
79
80
		wp_die();
81
	}
82
83
	/**
84
	 * @since 4.05
85
	 */
86
	private static function add_tracking_request() {
87
		$settings = FrmAppHelper::get_settings();
88
		if ( $settings->tracking ) {
89
			return;
90
		}
91
92
		$link = admin_url( 'admin.php?page=formidable-settings&t=misc_settings' );
93
94
		$message = new FrmInbox();
95
		$message->add_message(
96
			array(
97
				'key'     => 'usage',
98
				'message' => 'Gathering usage data allows us to improve Formidable. Your forms will be considered as we evaluate new features, judge the quality of an update, or determine if an improvement makes sense. You can always visit the <a href="' . esc_url( $link ) . '">Global Settings</a> and choose to stop sharing data. <a href="https://formidableforms.com/knowledgebase/global-settings-overview/#kb-usage-tracking" target="_blank" rel="noopener noreferrer">Read more about what data we collect</a>.',
99
				'subject' => __( 'Help Formidable improve with usage tracking', 'formidable' ),
100
				'cta'     => '<a href="#" class="button-secondary frm-button-secondary frm_inbox_dismiss">Dismiss</a> <a href="' . esc_url( $link ) . '" class="button-primary frm-button-primary frm_inbox_dismiss">Activate usage tracking</a>',
101
			)
102
		);
103
	}
104
}
105