Completed
Branch dependabot/composer/tijsverkoy... (491ea6)
by
unknown
32:00 queued 25:42
created
messages/messenger/admin_templates/event_switcher_row.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
             <?php esc_html_e('Actions', 'event_espresso'); ?>
48 48
         </label>
49 49
         <div class='event-message-actions'>
50
-            <?php echo wp_kses($create_button . $edit_button, AllowedTags::getWithFormTags()); ?>
50
+            <?php echo wp_kses($create_button.$edit_button, AllowedTags::getWithFormTags()); ?>
51 51
     </div>
52 52
     </td>
53 53
 </tr>
Please login to merge, or discard this patch.
admin_pages/transactions/templates/txn_admin_details_header.template.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@
 block discarded – undo
18 18
 <div class="ee-admin-page-nav-strip-wrap">
19 19
     <div class='ee-admin-page-nav-strip'>
20 20
     <?php
21
-    echo wp_kses($previous_transaction, AllowedTags::getAllowedTags());
22
-    echo '&nbsp;' . sprintf(
23
-        /* translators: %s: transaction number */
24
-        esc_html__('Transaction # %1$s', 'event_espresso'),
25
-        esc_html($txn_nmbr['value'])
26
-    ) . '&nbsp;';
27
-    echo wp_kses($next_transaction, AllowedTags::getAllowedTags());
28
-    ?>
21
+	echo wp_kses($previous_transaction, AllowedTags::getAllowedTags());
22
+	echo '&nbsp;' . sprintf(
23
+		/* translators: %s: transaction number */
24
+		esc_html__('Transaction # %1$s', 'event_espresso'),
25
+		esc_html($txn_nmbr['value'])
26
+	) . '&nbsp;';
27
+	echo wp_kses($next_transaction, AllowedTags::getAllowedTags());
28
+	?>
29 29
     </div>
30 30
 </div>
31 31
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@
 block discarded – undo
19 19
     <div class='ee-admin-page-nav-strip'>
20 20
     <?php
21 21
     echo wp_kses($previous_transaction, AllowedTags::getAllowedTags());
22
-    echo '&nbsp;' . sprintf(
22
+    echo '&nbsp;'.sprintf(
23 23
         /* translators: %s: transaction number */
24 24
         esc_html__('Transaction # %1$s', 'event_espresso'),
25 25
         esc_html($txn_nmbr['value'])
26
-    ) . '&nbsp;';
26
+    ).'&nbsp;';
27 27
     echo wp_kses($next_transaction, AllowedTags::getAllowedTags());
28 28
     ?>
29 29
     </div>
Please login to merge, or discard this patch.
templates/txn_admin_details_side_meta_box_registrant.template.php 3 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
 $avatar = get_avatar_url($prime_reg_email);
19 19
 ?>
20 20
 <div id="admin-side-mbox-primary-registrant-dv" class="admin-side-mbox-dv">
21
-<?php if (! empty($no_attendee_message)) : ?>
21
+<?php if ( ! empty($no_attendee_message)) : ?>
22 22
     <div>
23 23
         <?php echo esc_html($no_attendee_message); ?>
24 24
     </div>
25 25
 <?php else : ?>
26
-    <?php if (! empty($avatar)) : ?>
26
+    <?php if ( ! empty($avatar)) : ?>
27 27
     <div class="ee-admin-attendee-avatar">
28 28
         <img alt="profile pic for <?php echo esc_html($attendee_full_name); ?>" src="<?php echo esc_url_raw($avatar); ?>" />
29 29
     </div>
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
                 </a>
41 41
             </div>
42 42
         </div>
43
-        <?php if (! empty($prime_reg_phone)) : ?>
43
+        <?php if ( ! empty($prime_reg_phone)) : ?>
44 44
             <div class='ee-admin-attendee-phone'>
45 45
                 <div class='ee-admin-contact-details-with-dashicon'>
46 46
                     <span class='dashicons dashicons-phone'></span>
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
                 </div>
51 51
             </div>
52 52
         <?php endif; ?>
53
-        <?php if (! empty($formatted_address)) : ?>
53
+        <?php if ( ! empty($formatted_address)) : ?>
54 54
         <div class='ee-admin-attendee-address'>
55 55
             <div class='ee-admin-contact-details-with-dashicon'>
56 56
                 <span class='dashicons dashicons-location'></span>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,10 +22,13 @@
 block discarded – undo
22 22
     <div>
23 23
         <?php echo esc_html($no_attendee_message); ?>
24 24
     </div>
25
-<?php else : ?>
25
+<?php else {
26
+	: ?>
26 27
     <?php if (! empty($avatar)) : ?>
27 28
     <div class="ee-admin-attendee-avatar">
28
-        <img alt="profile pic for <?php echo esc_html($attendee_full_name); ?>" src="<?php echo esc_url_raw($avatar); ?>" />
29
+        <img alt="profile pic for <?php echo esc_html($attendee_full_name);
30
+}
31
+?>" src="<?php echo esc_url_raw($avatar); ?>" />
29 32
     </div>
30 33
     <?php endif; ?>
31 34
     <div class='admin-side-mbox-text-dv'>
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -65,11 +65,11 @@
 block discarded – undo
65 65
 endif;
66 66
 // only show if logged-in user has access
67 67
 if (
68
-    EE_Registry::instance()->CAP->current_user_can(
69
-        'ee_edit_contact',
70
-        'view_or_edit_contact_button',
71
-        $ATT_ID
72
-    )
68
+	EE_Registry::instance()->CAP->current_user_can(
69
+		'ee_edit_contact',
70
+		'view_or_edit_contact_button',
71
+		$ATT_ID
72
+	)
73 73
 ) : ?>
74 74
     <div class='ee-admin-button-row'>
75 75
         <a class="ee-aria-tooltip button button--small button--secondary" href="<?php echo esc_url_raw($edit_attendee_url); ?>"
Please login to merge, or discard this patch.
services/admin/notices/status_change/status_change_notice.template.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -24,94 +24,94 @@  discard block
 block discarded – undo
24 24
             <h3><?php esc_html_e('Important Notice Regarding Status Color Codes', 'event_espresso'); ?></h3>
25 25
             <p>
26 26
                 <?php esc_html_e(
27
-                    'In order to correct some inconsistencies in our event, datetime, and ticket status color codes, we have made the following changes:',
28
-                    'event_espresso'
29
-                ); ?>
27
+					'In order to correct some inconsistencies in our event, datetime, and ticket status color codes, we have made the following changes:',
28
+					'event_espresso'
29
+				); ?>
30 30
             </p>
31 31
             <ul>
32 32
                 <li class="ee-status-event">
33 33
                     <?php printf(
34
-                        esc_html__(
35
-                            'The Event, Datetime, and Ticket "Sold Out" status colors have changed from %1$sYellow%3$s to %2$sPurple%3$s',
36
-                            'event_espresso'
37
-                        ),
38
-                        '<span class="yellow pill">',
39
-                        '<span class="purple pill">',
40
-                        '</span>'
41
-                    ); ?>
34
+						esc_html__(
35
+							'The Event, Datetime, and Ticket "Sold Out" status colors have changed from %1$sYellow%3$s to %2$sPurple%3$s',
36
+							'event_espresso'
37
+						),
38
+						'<span class="yellow pill">',
39
+						'<span class="purple pill">',
40
+						'</span>'
41
+					); ?>
42 42
                 </li>
43 43
                 <li class="ee-status-event">
44 44
                     <?php printf(
45
-                        esc_html__(
46
-                            'The Event and Datetime "Postponed" status colors have changed from %1$sPurple%3$s to %2$sYellow%3$s',
47
-                            'event_espresso'
48
-                        ),
49
-                        '<span class="purple pill">',
50
-                        '<span class="yellow pill">',
51
-                        '</span>'
52
-                    ); ?>
45
+						esc_html__(
46
+							'The Event and Datetime "Postponed" status colors have changed from %1$sPurple%3$s to %2$sYellow%3$s',
47
+							'event_espresso'
48
+						),
49
+						'<span class="purple pill">',
50
+						'<span class="yellow pill">',
51
+						'</span>'
52
+					); ?>
53 53
                 </li>
54 54
                 <li class="ee-status-event">
55 55
                     <?php printf(
56
-                        esc_html__(
57
-                            'The Event "Inactive" and Ticket "Archived" status colors have changed from %1$sPurple%3$s to %2$sCharcoal%3$s',
58
-                            'event_espresso'
59
-                        ),
60
-                        '<span class="purple pill">',
61
-                        '<span class="charcoal pill">',
62
-                        '</span>'
63
-                    ); ?>
56
+						esc_html__(
57
+							'The Event "Inactive" and Ticket "Archived" status colors have changed from %1$sPurple%3$s to %2$sCharcoal%3$s',
58
+							'event_espresso'
59
+						),
60
+						'<span class="purple pill">',
61
+						'<span class="charcoal pill">',
62
+						'</span>'
63
+					); ?>
64 64
                 </li>
65 65
                 <li class="ee-status-message">
66 66
                     <?php printf(
67
-                        esc_html__(
68
-                            'The Message "Queued For Resending" status color has changed from %1$sYellow%3$s to %2$sBlue%3$s',
69
-                            'event_espresso'
70
-                        ),
71
-                        '<span class="yellow pill">',
72
-                        '<span class="blue pill">',
73
-                        '</span>'
74
-                    ); ?>
67
+						esc_html__(
68
+							'The Message "Queued For Resending" status color has changed from %1$sYellow%3$s to %2$sBlue%3$s',
69
+							'event_espresso'
70
+						),
71
+						'<span class="yellow pill">',
72
+						'<span class="blue pill">',
73
+						'</span>'
74
+					); ?>
75 75
                 </li>
76 76
                 <li class="ee-status-message">
77 77
                     <?php printf(
78
-                        esc_html__(
79
-                            'The Message "Messenger Is Executing" status color has changed from %1$sPink%3$s to %2$sGreen%3$s',
80
-                            'event_espresso'
81
-                        ),
82
-                        '<span class="pink pill">',
83
-                        '<span class="green pill">',
84
-                        '</span>'
85
-                    ); ?>
78
+						esc_html__(
79
+							'The Message "Messenger Is Executing" status color has changed from %1$sPink%3$s to %2$sGreen%3$s',
80
+							'event_espresso'
81
+						),
82
+						'<span class="pink pill">',
83
+						'<span class="green pill">',
84
+						'</span>'
85
+					); ?>
86 86
                 </li>
87 87
                 <li class="ee-status-message">
88 88
                     <?php printf(
89
-                        esc_html__(
90
-                            'The Message "Failed" status color has changed from %1$sRed%3$s to %2$sPink%3$s',
91
-                            'event_espresso'
92
-                        ),
93
-                        '<span class="red pill">',
94
-                        '<span class="pink pill">',
95
-                        '</span>'
96
-                    ); ?>
89
+						esc_html__(
90
+							'The Message "Failed" status color has changed from %1$sRed%3$s to %2$sPink%3$s',
91
+							'event_espresso'
92
+						),
93
+						'<span class="red pill">',
94
+						'<span class="pink pill">',
95
+						'</span>'
96
+					); ?>
97 97
                 </li>
98 98
                 <li class="ee-status-message">
99 99
                     <?php printf(
100
-                        esc_html__(
101
-                            'The Message "Debug only" status color has changed from %1$sYellow%3$s to %2$sRed%3$s',
102
-                            'event_espresso'
103
-                        ),
104
-                        '<span class="yellow pill">',
105
-                        '<span class="red pill">',
106
-                        '</span>'
107
-                    ); ?>
100
+						esc_html__(
101
+							'The Message "Debug only" status color has changed from %1$sYellow%3$s to %2$sRed%3$s',
102
+							'event_espresso'
103
+						),
104
+						'<span class="yellow pill">',
105
+						'<span class="red pill">',
106
+						'</span>'
107
+					); ?>
108 108
                 </li>
109 109
             </ul>
110 110
             <p>
111 111
                 <?php esc_html_e(
112
-                    'Please accept our sincere apologies for any inconvenience this might cause.',
113
-                    'event_espresso'
114
-                ); ?>
112
+					'Please accept our sincere apologies for any inconvenience this might cause.',
113
+					'event_espresso'
114
+				); ?>
115 115
             </p>
116 116
             <p class="ee-dismiss-notice-pg">
117 117
                 <button type="button"
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
                         id='ee-dismiss-notice-link'
121 121
                 >
122 122
                     <span class="pill pink"><?php
123
-                        esc_html_e('don\'t show this notice again please', 'event_espresso');
124
-                    ?></span>
123
+						esc_html_e('don\'t show this notice again please', 'event_espresso');
124
+					?></span>
125 125
                 </button>
126 126
             </p>
127 127
         </div>
Please login to merge, or discard this patch.
core/domain/services/admin/registrations/DatetimesForEventCheckIn.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -111,10 +111,10 @@
 block discarded – undo
111 111
             $where = [
112 112
                 'Registration.REG_ID' => ['!=', null],
113 113
             ];
114
-            if (! $this->caps->current_user_can('ee_read_private_events', 'get_events')) {
114
+            if ( ! $this->caps->current_user_can('ee_read_private_events', 'get_events')) {
115 115
                 $where['status**'] = ['!=', 'private'];
116 116
             }
117
-            if (! $this->caps->current_user_can('ee_read_others_events', 'get_events')) {
117
+            if ( ! $this->caps->current_user_can('ee_read_others_events', 'get_events')) {
118 118
                 $where['EVT_wp_user'] = get_current_user_id();
119 119
             }
120 120
             $this->all_events = EEM_Event::instance()->get_all(
Please login to merge, or discard this patch.
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -12,189 +12,189 @@
 block discarded – undo
12 12
 
13 13
 class DatetimesForEventCheckIn
14 14
 {
15
-    /**
16
-     * @var EE_Capabilities $caps
17
-     */
18
-    public $caps;
19
-
20
-    /**
21
-     * @var EE_Event
22
-     */
23
-    protected $event;
24
-
25
-    /**
26
-     * @var EE_Event[]
27
-     */
28
-    protected $all_events;
29
-
30
-    /**
31
-     * @var EE_Datetime[]
32
-     */
33
-    protected $datetimes;
34
-
35
-    /**
36
-     * @var int
37
-     */
38
-    private $start_date_offset;
39
-
40
-
41
-    /**
42
-     * @param EE_Capabilities $capabilities
43
-     * @param EE_Event|null   $event
44
-     */
45
-    public function __construct(EE_Capabilities $capabilities, ?EE_Event $event = null)
46
-    {
47
-        $this->event             = $event;
48
-        $this->caps              = $capabilities;
49
-        $this->start_date_offset = absint(
50
-            apply_filters(
51
-                'FHEE__EventEspresso_core_domain_services_admin_registrations_DatetimesForEventCheckIn__start_date_offset',
52
-                HOUR_IN_SECONDS * 2,
53
-                $this->event
54
-            )
55
-        );
56
-    }
57
-
58
-
59
-    /**
60
-     * @param int $event_id
61
-     * @return DatetimesForEventCheckIn
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public static function fromEventID(int $event_id): DatetimesForEventCheckIn
66
-    {
67
-        /** @var EE_Event $event */
68
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
69
-        return new DatetimesForEventCheckIn(EE_Capabilities::instance(), $event);
70
-    }
71
-
72
-
73
-    /**
74
-     * @param EE_Event $event
75
-     * @return DatetimesForEventCheckIn
76
-     */
77
-    public static function fromEvent(EE_Event $event): DatetimesForEventCheckIn
78
-    {
79
-        return new DatetimesForEventCheckIn(EE_Capabilities::instance(), $event);
80
-    }
81
-
82
-
83
-    /**
84
-     * @param EE_Registration $registration
85
-     * @return DatetimesForEventCheckIn
86
-     * @throws EE_Error
87
-     */
88
-    public static function fromRegistration(EE_Registration $registration): DatetimesForEventCheckIn
89
-    {
90
-        return new DatetimesForEventCheckIn(EE_Capabilities::instance(), $registration->event());
91
-    }
92
-
93
-
94
-    /**
95
-     * @return EE_Event
96
-     */
97
-    public function event(): EE_Event
98
-    {
99
-        return $this->event;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return EE_Event[]
105
-     * @throws EE_Error
106
-     * @throws ReflectionException
107
-     */
108
-    public function getAllDatetimesForAllEvents(): array
109
-    {
110
-        return $this->getAllEvents();
111
-    }
112
-
113
-
114
-    /**
115
-     * @return EE_Event[]
116
-     * @throws EE_Error
117
-     * @throws ReflectionException
118
-     */
119
-    public function getAllEvents(): array
120
-    {
121
-        if ($this->all_events === null) {
122
-            $where = [
123
-                'Registration.REG_ID' => ['!=', null],
124
-            ];
125
-            if (! $this->caps->current_user_can('ee_read_private_events', 'get_events')) {
126
-                $where['status**'] = ['!=', 'private'];
127
-            }
128
-            if (! $this->caps->current_user_can('ee_read_others_events', 'get_events')) {
129
-                $where['EVT_wp_user'] = get_current_user_id();
130
-            }
131
-            $this->all_events = EEM_Event::instance()->get_all(
132
-                [
133
-                    $where,
134
-                    'order_by' => ['Datetime.DTT_EVT_start' => 'DESC'],
135
-                    'limit' => 100
136
-                ]
137
-            );
138
-        }
139
-        return $this->all_events;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param bool|null $hide_expired
145
-     * @param bool|null $hide_upcoming
146
-     * @return array
147
-     * @throws EE_Error
148
-     * @throws ReflectionException
149
-     */
150
-    public function getAllDatetimesForEvent(?bool $hide_expired = false, ?bool $hide_upcoming = false): array
151
-    {
152
-        // we're applying a filterable offset to the start date
153
-        // so that check-ins can begin before the event actually starts
154
-        $start_date   = $hide_upcoming ? time() + $this->start_date_offset : null;
155
-        $end_date     = $hide_expired ? time() : null;
156
-        $query_params = [
157
-            'order_by' => ['DTT_EVT_start' => 'ASC'],
158
-        ];
159
-
160
-        if ($start_date) {
161
-            $query_params[0]['DTT_EVT_start'] = ['<', $start_date];
162
-        }
163
-        if ($end_date) {
164
-            $query_params[0]['DTT_EVT_end'] = ['>', $end_date];
165
-        }
166
-        return $this->event instanceof EE_Event
167
-            ? $this->event->datetimes($query_params)
168
-            : [];
169
-    }
170
-
171
-
172
-    /**
173
-     * @param int|null  $DTT_ID If specific datetime ID is supplied, will return that date, but only if it is active.
174
-     *                          If no ID is supplied but event only has one related datetime, then it will be returned.
175
-     *                          If the above conditions are not met, then function will return null.
176
-     * @param bool|null $hide_expired
177
-     * @param bool|null $hide_upcoming
178
-     * @return EE_Datetime|null
179
-     * @throws EE_Error
180
-     * @throws ReflectionException
181
-     */
182
-    public function getOneDatetimeForEvent(
183
-        ?int $DTT_ID = 0,
184
-        ?bool $hide_expired = false,
185
-        ?bool $hide_upcoming = false
186
-    ): ?EE_Datetime {
187
-        if (empty($this->datetimes)) {
188
-            $this->datetimes = $this->getAllDatetimesForEvent($hide_expired, $hide_upcoming);
189
-        }
190
-        if ($DTT_ID) {
191
-            foreach ($this->datetimes as $datetime) {
192
-                if ($datetime instanceof EE_Datetime && $datetime->ID() === $DTT_ID) {
193
-                    return $datetime;
194
-                }
195
-            }
196
-            return null;
197
-        }
198
-        return count($this->datetimes) === 1 ? reset($this->datetimes) : null;
199
-    }
15
+	/**
16
+	 * @var EE_Capabilities $caps
17
+	 */
18
+	public $caps;
19
+
20
+	/**
21
+	 * @var EE_Event
22
+	 */
23
+	protected $event;
24
+
25
+	/**
26
+	 * @var EE_Event[]
27
+	 */
28
+	protected $all_events;
29
+
30
+	/**
31
+	 * @var EE_Datetime[]
32
+	 */
33
+	protected $datetimes;
34
+
35
+	/**
36
+	 * @var int
37
+	 */
38
+	private $start_date_offset;
39
+
40
+
41
+	/**
42
+	 * @param EE_Capabilities $capabilities
43
+	 * @param EE_Event|null   $event
44
+	 */
45
+	public function __construct(EE_Capabilities $capabilities, ?EE_Event $event = null)
46
+	{
47
+		$this->event             = $event;
48
+		$this->caps              = $capabilities;
49
+		$this->start_date_offset = absint(
50
+			apply_filters(
51
+				'FHEE__EventEspresso_core_domain_services_admin_registrations_DatetimesForEventCheckIn__start_date_offset',
52
+				HOUR_IN_SECONDS * 2,
53
+				$this->event
54
+			)
55
+		);
56
+	}
57
+
58
+
59
+	/**
60
+	 * @param int $event_id
61
+	 * @return DatetimesForEventCheckIn
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public static function fromEventID(int $event_id): DatetimesForEventCheckIn
66
+	{
67
+		/** @var EE_Event $event */
68
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
69
+		return new DatetimesForEventCheckIn(EE_Capabilities::instance(), $event);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @param EE_Event $event
75
+	 * @return DatetimesForEventCheckIn
76
+	 */
77
+	public static function fromEvent(EE_Event $event): DatetimesForEventCheckIn
78
+	{
79
+		return new DatetimesForEventCheckIn(EE_Capabilities::instance(), $event);
80
+	}
81
+
82
+
83
+	/**
84
+	 * @param EE_Registration $registration
85
+	 * @return DatetimesForEventCheckIn
86
+	 * @throws EE_Error
87
+	 */
88
+	public static function fromRegistration(EE_Registration $registration): DatetimesForEventCheckIn
89
+	{
90
+		return new DatetimesForEventCheckIn(EE_Capabilities::instance(), $registration->event());
91
+	}
92
+
93
+
94
+	/**
95
+	 * @return EE_Event
96
+	 */
97
+	public function event(): EE_Event
98
+	{
99
+		return $this->event;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return EE_Event[]
105
+	 * @throws EE_Error
106
+	 * @throws ReflectionException
107
+	 */
108
+	public function getAllDatetimesForAllEvents(): array
109
+	{
110
+		return $this->getAllEvents();
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return EE_Event[]
116
+	 * @throws EE_Error
117
+	 * @throws ReflectionException
118
+	 */
119
+	public function getAllEvents(): array
120
+	{
121
+		if ($this->all_events === null) {
122
+			$where = [
123
+				'Registration.REG_ID' => ['!=', null],
124
+			];
125
+			if (! $this->caps->current_user_can('ee_read_private_events', 'get_events')) {
126
+				$where['status**'] = ['!=', 'private'];
127
+			}
128
+			if (! $this->caps->current_user_can('ee_read_others_events', 'get_events')) {
129
+				$where['EVT_wp_user'] = get_current_user_id();
130
+			}
131
+			$this->all_events = EEM_Event::instance()->get_all(
132
+				[
133
+					$where,
134
+					'order_by' => ['Datetime.DTT_EVT_start' => 'DESC'],
135
+					'limit' => 100
136
+				]
137
+			);
138
+		}
139
+		return $this->all_events;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param bool|null $hide_expired
145
+	 * @param bool|null $hide_upcoming
146
+	 * @return array
147
+	 * @throws EE_Error
148
+	 * @throws ReflectionException
149
+	 */
150
+	public function getAllDatetimesForEvent(?bool $hide_expired = false, ?bool $hide_upcoming = false): array
151
+	{
152
+		// we're applying a filterable offset to the start date
153
+		// so that check-ins can begin before the event actually starts
154
+		$start_date   = $hide_upcoming ? time() + $this->start_date_offset : null;
155
+		$end_date     = $hide_expired ? time() : null;
156
+		$query_params = [
157
+			'order_by' => ['DTT_EVT_start' => 'ASC'],
158
+		];
159
+
160
+		if ($start_date) {
161
+			$query_params[0]['DTT_EVT_start'] = ['<', $start_date];
162
+		}
163
+		if ($end_date) {
164
+			$query_params[0]['DTT_EVT_end'] = ['>', $end_date];
165
+		}
166
+		return $this->event instanceof EE_Event
167
+			? $this->event->datetimes($query_params)
168
+			: [];
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param int|null  $DTT_ID If specific datetime ID is supplied, will return that date, but only if it is active.
174
+	 *                          If no ID is supplied but event only has one related datetime, then it will be returned.
175
+	 *                          If the above conditions are not met, then function will return null.
176
+	 * @param bool|null $hide_expired
177
+	 * @param bool|null $hide_upcoming
178
+	 * @return EE_Datetime|null
179
+	 * @throws EE_Error
180
+	 * @throws ReflectionException
181
+	 */
182
+	public function getOneDatetimeForEvent(
183
+		?int $DTT_ID = 0,
184
+		?bool $hide_expired = false,
185
+		?bool $hide_upcoming = false
186
+	): ?EE_Datetime {
187
+		if (empty($this->datetimes)) {
188
+			$this->datetimes = $this->getAllDatetimesForEvent($hide_expired, $hide_upcoming);
189
+		}
190
+		if ($DTT_ID) {
191
+			foreach ($this->datetimes as $datetime) {
192
+				if ($datetime instanceof EE_Datetime && $datetime->ID() === $DTT_ID) {
193
+					return $datetime;
194
+				}
195
+			}
196
+			return null;
197
+		}
198
+		return count($this->datetimes) === 1 ? reset($this->datetimes) : null;
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Select_Input.input.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,16 +13,16 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Select_Input extends EE_Form_Input_With_Options_Base
15 15
 {
16
-    /**
17
-     * @param array $answer_options
18
-     * @param array $input_settings
19
-     */
20
-    public function __construct($answer_options, $input_settings = array())
21
-    {
22
-        $this->_set_display_strategy(new EE_Select_Display_Strategy($answer_options));
23
-        $this->_add_validation_strategy(
24
-            new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null)
25
-        );
26
-        parent::__construct($answer_options, $input_settings);
27
-    }
16
+	/**
17
+	 * @param array $answer_options
18
+	 * @param array $input_settings
19
+	 */
20
+	public function __construct($answer_options, $input_settings = array())
21
+	{
22
+		$this->_set_display_strategy(new EE_Select_Display_Strategy($answer_options));
23
+		$this->_add_validation_strategy(
24
+			new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null)
25
+		);
26
+		parent::__construct($answer_options, $input_settings);
27
+	}
28 28
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Radio_Button_Input.input.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,17 +11,17 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Radio_Button_Input extends EE_Form_Input_With_Options_Base
13 13
 {
14
-    /**
15
-     * @param array $answer_options
16
-     * @param array $input_settings
17
-     */
18
-    public function __construct($answer_options, $input_settings = array())
19
-    {
20
-        $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy());
21
-        $this->_add_validation_strategy(
22
-            new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null)
23
-        );
24
-        $this->_multiple_selections = false;
25
-        parent::__construct($answer_options, $input_settings);
26
-    }
14
+	/**
15
+	 * @param array $answer_options
16
+	 * @param array $input_settings
17
+	 */
18
+	public function __construct($answer_options, $input_settings = array())
19
+	{
20
+		$this->_set_display_strategy(new EE_Radio_Button_Display_Strategy());
21
+		$this->_add_validation_strategy(
22
+			new EE_Enum_Validation_Strategy($input_settings['validation_error_message'] ?? null)
23
+		);
24
+		$this->_multiple_selections = false;
25
+		parent::__construct($answer_options, $input_settings);
26
+	}
27 27
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/templates/import_page.template.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <div class="import-area">
2 2
     <div class="important-notice">
3 3
         <?php esc_html_e(
4
-            'The import feature has been disabled because of bugs. It is expected to be put back in place soon.',
5
-            'event_espresso'
6
-        ); ?>
4
+			'The import feature has been disabled because of bugs. It is expected to be put back in place soon.',
5
+			'event_espresso'
6
+		); ?>
7 7
     </div>
8 8
     <?php // echo wp_kses($form, \EventEspresso\core\services\request\sanitizers\AllowedTags::getWithFormTags()); ?>
9 9
 </div>
Please login to merge, or discard this patch.
modules/ical/EED_Ical.module.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -89,24 +89,24 @@  discard block
 block discarded – undo
89 89
             switch ($iCal_type) {
90 90
                 // submit buttons appear as buttons and are very compatible with a theme's style
91 91
                 case 'submit':
92
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
93
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
92
+                    $html .= '<form id="download-iCal-frm-'.$datetime->ID();
93
+                    $html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >';
94 94
                     $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
95
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
95
+                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'"/>';
96 96
                     $html .= '</form>';
97 97
                     break;
98 98
                 // buttons are just links that have been styled to appear as buttons,
99 99
                 // but may not be blend with a theme as well as submit buttons
100 100
                 case 'button':
101
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
102
-                    $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
101
+                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL;
102
+                    $html .= '" title="'.esc_html__('Add to iCal Calendar', 'event_espresso').'">';
103 103
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
104 104
                     $html .= '</a>';
105 105
                     break;
106 106
                 // links are just links that use the calendar dashicon
107 107
                 case 'icon':
108
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
109
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
108
+                    $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="';
109
+                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'">';
110 110
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
111 111
                     $html .= '</a>';
112 112
                     break;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                     }
148 148
 
149 149
                     // Generate filename
150
-                    $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
150
+                    $filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics';
151 151
 
152 152
                     // Check the datetime status has not been cancelled and set the ics value accordingly
153 153
                     $status = $datetime->get_active_status();
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                     // Create array of ics details, escape strings, convert timestamps to ics format, etc
157 157
                     $ics_data = [
158 158
                         'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
159
-                        'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
159
+                        'UID'            => md5($event->name().$event->ID().$datetime->ID()),
160 160
                         'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
161 161
                         'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
162 162
                         'LOCATION'       => $location,
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
                     foreach ($ics_data as $key => $value) {
178 178
                         // Description is escaped differently from all all values
179 179
                         if ($key === 'DESCRIPTION') {
180
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
180
+                            $ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
181 181
                         } else {
182
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
182
+                            $ics_data[$key] = EED_Ical::_escape_ICal_data($value);
183 183
                         }
184 184
                     }
185 185
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
                     // set headers
193 193
                     header('Content-type: text/calendar; charset=utf-8');
194
-                    header('Content-Disposition: attachment; filename="' . $filename . '"');
194
+                    header('Content-Disposition: attachment; filename="'.$filename.'"');
195 195
                     header('Cache-Control: private, max-age=0, must-revalidate');
196 196
                     header('Pragma: public');
197 197
                     header('Content-Type: application/octet-stream');
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
                     // Output all remaining values from ics_data.
211 211
                     foreach ($ics_data as $key => $value) {
212
-                        echo wp_kses($key . ':' . $value, AllowedTags::getAllowedTags()) . "\r\n";
212
+                        echo wp_kses($key.':'.$value, AllowedTags::getAllowedTags())."\r\n";
213 213
                     }
214 214
 
215 215
                     echo "END:VEVENT\r\n";
Please login to merge, or discard this patch.
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -14,235 +14,235 @@
 block discarded – undo
14 14
  */
15 15
 class EED_Ical extends EED_Module
16 16
 {
17
-    const iCal_datetime_format = 'Ymd\THis\Z';
18
-
19
-
20
-    /**
21
-     * @return EED_Ical|EED_Module
22
-     * @throws EE_Error
23
-     * @throws ReflectionException
24
-     */
25
-    public static function instance()
26
-    {
27
-        return parent::get_instance(__CLASS__);
28
-    }
29
-
30
-
31
-    /**
32
-     *    set_hooks - for hooking into EE Core, other modules, etc
33
-     *
34
-     * @return    void
35
-     */
36
-    public static function set_hooks()
37
-    {
38
-        // create download buttons
39
-        add_filter(
40
-            'FHEE__espresso_list_of_event_dates__datetime_html',
41
-            ['EED_Ical', 'generate_add_to_iCal_button'],
42
-            10,
43
-            2
44
-        );
45
-        // process ics download request
46
-        EED_Module::registerRoute('download_ics_file', 'EED_Ical', 'download_ics_file');
47
-    }
48
-
49
-
50
-    /**
51
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
52
-     *
53
-     * @return    void
54
-     */
55
-    public static function set_hooks_admin()
56
-    {
57
-    }
58
-
59
-
60
-    /**
61
-     *    run - initial module setup
62
-     *
63
-     * @param WP $WP
64
-     * @return    void
65
-     */
66
-    public function run($WP)
67
-    {
68
-    }
69
-
70
-
71
-    /**
72
-     * @param $html
73
-     * @param $datetime
74
-     * @return string
75
-     * @throws EE_Error
76
-     * @throws ReflectionException
77
-     */
78
-    public static function generate_add_to_iCal_button($html, $datetime)
79
-    {
80
-        // first verify a proper datetime object has been received
81
-        if ($datetime instanceof EE_Datetime) {
82
-            // set whether a link or submit button is shown
83
-            $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
84
-            // generate a link to the route we registered in set_hooks()
85
-            $URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url());
86
-            $URL = esc_url_Raw($URL);
87
-            // what type ?
88
-            switch ($iCal_type) {
89
-                // submit buttons appear as buttons and are very compatible with a theme's style
90
-                case 'submit':
91
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
92
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
93
-                    $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
94
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
95
-                    $html .= '</form>';
96
-                    break;
97
-                // buttons are just links that have been styled to appear as buttons,
98
-                // but may not be blend with a theme as well as submit buttons
99
-                case 'button':
100
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
101
-                    $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
102
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
103
-                    $html .= '</a>';
104
-                    break;
105
-                // links are just links that use the calendar dashicon
106
-                case 'icon':
107
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
108
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
109
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
110
-                    $html .= '</a>';
111
-                    break;
112
-            }
113
-        }
114
-        return $html;
115
-    }
116
-
117
-
118
-    /**
119
-     * @return void
120
-     * @throws EE_Error
121
-     * @throws ReflectionException
122
-     */
123
-    public static function download_ics_file()
124
-    {
125
-        $request = self::getRequest();
126
-        if ($request->requestParamIsSet('ics_id')) {
127
-            $DTT_ID   = $request->getRequestParam('ics_id', 0, 'int');
128
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
129
-            if ($datetime instanceof EE_Datetime) {
130
-                // get related event, venues, and event categories
131
-                $event = $datetime->event();
132
-                if ($event instanceof EE_Event) {
133
-                    // get related category Term object and it's name
134
-                    $category = $event->first_event_category();
135
-                    if ($category instanceof EE_Term) {
136
-                        $category = $category->name();
137
-                    }
138
-                    $location = '';
139
-                    // get first related venue and convert to CSV string
140
-                    $venue = $event->venues(['limit' => 1]);
141
-                    if (is_array($venue) && ! empty($venue)) {
142
-                        $venue = array_shift($venue);
143
-                        if ($venue instanceof EE_Venue) {
144
-                            $location = espresso_venue_raw_address('inline', $venue->ID(), false);
145
-                        }
146
-                    }
147
-
148
-                    // Generate filename
149
-                    $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
150
-
151
-                    // Check the datetime status has not been cancelled and set the ics value accordingly
152
-                    $status = $datetime->get_active_status();
153
-                    $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
154
-
155
-                    // Create array of ics details, escape strings, convert timestamps to ics format, etc
156
-                    $ics_data = [
157
-                        'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
158
-                        'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
159
-                        'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
160
-                        'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
161
-                        'LOCATION'       => $location,
162
-                        'SUMMARY'        => $event->name(),
163
-                        'DESCRIPTION'    => wp_strip_all_tags($event->description()),
164
-                        'STATUS'         => $status,
165
-                        'CATEGORIES'     => $category,
166
-                        'URL;VALUE=URI'  => get_permalink($event->ID()),
167
-                        'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
168
-                        'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
169
-                    ];
170
-
171
-                    // Filter the values used within the ics output.
172
-                    // NOTE - all values within ics_data will be escaped automatically.
173
-                    $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
174
-
175
-                    // Escape all ics data
176
-                    foreach ($ics_data as $key => $value) {
177
-                        // Description is escaped differently from all all values
178
-                        if ($key === 'DESCRIPTION') {
179
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
180
-                        } else {
181
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
182
-                        }
183
-                    }
184
-
185
-                    // Pull the organizer name from ics_data and remove it from the array.
186
-                    $organizer_name = isset($ics_data['ORGANIZER_NAME'])
187
-                        ? $ics_data['ORGANIZER_NAME']
188
-                        : '';
189
-                    unset($ics_data['ORGANIZER_NAME']);
190
-
191
-                    // set headers
192
-                    header('Content-type: text/calendar; charset=utf-8');
193
-                    header('Content-Disposition: attachment; filename="' . $filename . '"');
194
-                    header('Cache-Control: private, max-age=0, must-revalidate');
195
-                    header('Pragma: public');
196
-                    header('Content-Type: application/octet-stream');
197
-                    header('Content-Type: application/force-download');
198
-                    header('Cache-Control: no-cache, must-revalidate');
199
-                    header('Content-Transfer-Encoding: binary');
200
-                    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
201
-                    ini_set('zlib.output_compression', '0');
202
-                    // echo the output
203
-                    echo "BEGIN:VCALENDAR\r\n";
204
-                    echo "VERSION:2.0\r\n";
205
-                    echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
206
-                    echo "CALSCALE:GREGORIAN\r\n";
207
-                    echo "BEGIN:VEVENT\r\n";
208
-
209
-                    // Output all remaining values from ics_data.
210
-                    foreach ($ics_data as $key => $value) {
211
-                        echo wp_kses($key . ':' . $value, AllowedTags::getAllowedTags()) . "\r\n";
212
-                    }
213
-
214
-                    echo "END:VEVENT\r\n";
215
-                    echo "END:VCALENDAR\r\n";
216
-                }
217
-            }
218
-        }
219
-        die();
220
-    }
221
-
222
-
223
-    /**
224
-     *    _escape_ICal_data
225
-     *
226
-     * @param string $string
227
-     * @return    string
228
-     */
229
-    private static function _escape_ICal_data($string = '')
230
-    {
231
-        return preg_replace('/([\,;])/', '\\\$1', $string);
232
-    }
233
-
234
-
235
-    /**
236
-     *    _escape_ICal_description
237
-     *
238
-     * @param string $description
239
-     * @return    string
240
-     */
241
-    private static function _escape_ICal_description($description = '')
242
-    {
243
-        // Escape special chars within the description
244
-        $description = EED_Ical::_escape_ICal_data($description);
245
-        // Remove line breaks and output in iCal format
246
-        return str_replace(["\r\n", "\n"], '\n', $description);
247
-    }
17
+	const iCal_datetime_format = 'Ymd\THis\Z';
18
+
19
+
20
+	/**
21
+	 * @return EED_Ical|EED_Module
22
+	 * @throws EE_Error
23
+	 * @throws ReflectionException
24
+	 */
25
+	public static function instance()
26
+	{
27
+		return parent::get_instance(__CLASS__);
28
+	}
29
+
30
+
31
+	/**
32
+	 *    set_hooks - for hooking into EE Core, other modules, etc
33
+	 *
34
+	 * @return    void
35
+	 */
36
+	public static function set_hooks()
37
+	{
38
+		// create download buttons
39
+		add_filter(
40
+			'FHEE__espresso_list_of_event_dates__datetime_html',
41
+			['EED_Ical', 'generate_add_to_iCal_button'],
42
+			10,
43
+			2
44
+		);
45
+		// process ics download request
46
+		EED_Module::registerRoute('download_ics_file', 'EED_Ical', 'download_ics_file');
47
+	}
48
+
49
+
50
+	/**
51
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
52
+	 *
53
+	 * @return    void
54
+	 */
55
+	public static function set_hooks_admin()
56
+	{
57
+	}
58
+
59
+
60
+	/**
61
+	 *    run - initial module setup
62
+	 *
63
+	 * @param WP $WP
64
+	 * @return    void
65
+	 */
66
+	public function run($WP)
67
+	{
68
+	}
69
+
70
+
71
+	/**
72
+	 * @param $html
73
+	 * @param $datetime
74
+	 * @return string
75
+	 * @throws EE_Error
76
+	 * @throws ReflectionException
77
+	 */
78
+	public static function generate_add_to_iCal_button($html, $datetime)
79
+	{
80
+		// first verify a proper datetime object has been received
81
+		if ($datetime instanceof EE_Datetime) {
82
+			// set whether a link or submit button is shown
83
+			$iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
84
+			// generate a link to the route we registered in set_hooks()
85
+			$URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url());
86
+			$URL = esc_url_Raw($URL);
87
+			// what type ?
88
+			switch ($iCal_type) {
89
+				// submit buttons appear as buttons and are very compatible with a theme's style
90
+				case 'submit':
91
+					$html .= '<form id="download-iCal-frm-' . $datetime->ID();
92
+					$html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
93
+					$html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
94
+					$html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
95
+					$html .= '</form>';
96
+					break;
97
+				// buttons are just links that have been styled to appear as buttons,
98
+				// but may not be blend with a theme as well as submit buttons
99
+				case 'button':
100
+					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
101
+					$html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
102
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
103
+					$html .= '</a>';
104
+					break;
105
+				// links are just links that use the calendar dashicon
106
+				case 'icon':
107
+					$html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
108
+					$html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
109
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
110
+					$html .= '</a>';
111
+					break;
112
+			}
113
+		}
114
+		return $html;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return void
120
+	 * @throws EE_Error
121
+	 * @throws ReflectionException
122
+	 */
123
+	public static function download_ics_file()
124
+	{
125
+		$request = self::getRequest();
126
+		if ($request->requestParamIsSet('ics_id')) {
127
+			$DTT_ID   = $request->getRequestParam('ics_id', 0, 'int');
128
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
129
+			if ($datetime instanceof EE_Datetime) {
130
+				// get related event, venues, and event categories
131
+				$event = $datetime->event();
132
+				if ($event instanceof EE_Event) {
133
+					// get related category Term object and it's name
134
+					$category = $event->first_event_category();
135
+					if ($category instanceof EE_Term) {
136
+						$category = $category->name();
137
+					}
138
+					$location = '';
139
+					// get first related venue and convert to CSV string
140
+					$venue = $event->venues(['limit' => 1]);
141
+					if (is_array($venue) && ! empty($venue)) {
142
+						$venue = array_shift($venue);
143
+						if ($venue instanceof EE_Venue) {
144
+							$location = espresso_venue_raw_address('inline', $venue->ID(), false);
145
+						}
146
+					}
147
+
148
+					// Generate filename
149
+					$filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
150
+
151
+					// Check the datetime status has not been cancelled and set the ics value accordingly
152
+					$status = $datetime->get_active_status();
153
+					$status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
154
+
155
+					// Create array of ics details, escape strings, convert timestamps to ics format, etc
156
+					$ics_data = [
157
+						'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
158
+						'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
159
+						'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
160
+						'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
161
+						'LOCATION'       => $location,
162
+						'SUMMARY'        => $event->name(),
163
+						'DESCRIPTION'    => wp_strip_all_tags($event->description()),
164
+						'STATUS'         => $status,
165
+						'CATEGORIES'     => $category,
166
+						'URL;VALUE=URI'  => get_permalink($event->ID()),
167
+						'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
168
+						'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
169
+					];
170
+
171
+					// Filter the values used within the ics output.
172
+					// NOTE - all values within ics_data will be escaped automatically.
173
+					$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
174
+
175
+					// Escape all ics data
176
+					foreach ($ics_data as $key => $value) {
177
+						// Description is escaped differently from all all values
178
+						if ($key === 'DESCRIPTION') {
179
+							$ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
180
+						} else {
181
+							$ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
182
+						}
183
+					}
184
+
185
+					// Pull the organizer name from ics_data and remove it from the array.
186
+					$organizer_name = isset($ics_data['ORGANIZER_NAME'])
187
+						? $ics_data['ORGANIZER_NAME']
188
+						: '';
189
+					unset($ics_data['ORGANIZER_NAME']);
190
+
191
+					// set headers
192
+					header('Content-type: text/calendar; charset=utf-8');
193
+					header('Content-Disposition: attachment; filename="' . $filename . '"');
194
+					header('Cache-Control: private, max-age=0, must-revalidate');
195
+					header('Pragma: public');
196
+					header('Content-Type: application/octet-stream');
197
+					header('Content-Type: application/force-download');
198
+					header('Cache-Control: no-cache, must-revalidate');
199
+					header('Content-Transfer-Encoding: binary');
200
+					header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
201
+					ini_set('zlib.output_compression', '0');
202
+					// echo the output
203
+					echo "BEGIN:VCALENDAR\r\n";
204
+					echo "VERSION:2.0\r\n";
205
+					echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
206
+					echo "CALSCALE:GREGORIAN\r\n";
207
+					echo "BEGIN:VEVENT\r\n";
208
+
209
+					// Output all remaining values from ics_data.
210
+					foreach ($ics_data as $key => $value) {
211
+						echo wp_kses($key . ':' . $value, AllowedTags::getAllowedTags()) . "\r\n";
212
+					}
213
+
214
+					echo "END:VEVENT\r\n";
215
+					echo "END:VCALENDAR\r\n";
216
+				}
217
+			}
218
+		}
219
+		die();
220
+	}
221
+
222
+
223
+	/**
224
+	 *    _escape_ICal_data
225
+	 *
226
+	 * @param string $string
227
+	 * @return    string
228
+	 */
229
+	private static function _escape_ICal_data($string = '')
230
+	{
231
+		return preg_replace('/([\,;])/', '\\\$1', $string);
232
+	}
233
+
234
+
235
+	/**
236
+	 *    _escape_ICal_description
237
+	 *
238
+	 * @param string $description
239
+	 * @return    string
240
+	 */
241
+	private static function _escape_ICal_description($description = '')
242
+	{
243
+		// Escape special chars within the description
244
+		$description = EED_Ical::_escape_ICal_data($description);
245
+		// Remove line breaks and output in iCal format
246
+		return str_replace(["\r\n", "\n"], '\n', $description);
247
+	}
248 248
 }
Please login to merge, or discard this patch.