Completed
Push — release-2.1 ( d0ec39...ad74d9 )
by Jeremy
15s
created
Sources/tasks/CreatePost-Notify.php 1 patch
Braces   +74 added lines, -54 removed lines patch added patch discarded remove patch
@@ -96,8 +96,9 @@  discard block
 block discarded – undo
96 96
 		while ($row = $smcFunc['db_fetch_assoc']($request))
97 97
 		{
98 98
 			$groups = array_merge(array($row['id_group'], $row['id_post_group']), (empty($row['additional_groups']) ? array() : explode(',', $row['additional_groups'])));
99
-			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0)
100
-				continue;
99
+			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) {
100
+							continue;
101
+			}
101 102
 
102 103
 			$members[] = $row['id_member'];
103 104
 			$watched[$row['id_member']] = $row;
@@ -105,8 +106,9 @@  discard block
 block discarded – undo
105 106
 
106 107
 		$smcFunc['db_free_result']($request);
107 108
 
108
-		if (empty($members))
109
-			return true;
109
+		if (empty($members)) {
110
+					return true;
111
+		}
110 112
 
111 113
 		$members = array_unique($members);
112 114
 		$prefs = getNotifyPrefs($members, '', true);
@@ -122,8 +124,9 @@  discard block
 block discarded – undo
122 124
 		self::handleQuoteNotifications($msgOptions, $posterOptions, $quotedMembers, $prefs, $done_members, $alert_rows);
123 125
 
124 126
 		// Save ourselves a bit of work in the big loop below
125
-		foreach ($done_members as $done_member)
126
-			unset($watched[$done_member]);
127
+		foreach ($done_members as $done_member) {
128
+					unset($watched[$done_member]);
129
+		}
127 130
 
128 131
 		// Handle rest of the notifications for watched topics and boards
129 132
 		foreach ($watched as $member => $data)
@@ -132,26 +135,31 @@  discard block
 block discarded – undo
132 135
 			$notify_types = !empty($prefs[$member]['msg_notify_type']) ? $prefs[$member]['msg_notify_type'] : self::NOTIFY_TYPE_REPLY_AND_MODIFY;
133 136
 
134 137
 			// Don't send a notification if the watching member ignored the member who made the action.
135
-			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list'])))
136
-				continue;
137
-			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started'])
138
-				continue;
139
-			elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id'])
140
-				continue;
141
-			elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES)
142
-				continue;
143
-			elseif ($notify_types == self::NOTIFY_TYPE_NOTHING)
144
-				continue;
138
+			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) {
139
+							continue;
140
+			}
141
+			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started']) {
142
+							continue;
143
+			} elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) {
144
+							continue;
145
+			} elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES) {
146
+							continue;
147
+			} elseif ($notify_types == self::NOTIFY_TYPE_NOTHING) {
148
+							continue;
149
+			}
145 150
 
146 151
 			// Don't send a notification if they don't want any...
147
-			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST)))
148
-				continue;
152
+			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST))) {
153
+							continue;
154
+			}
149 155
 			// ... or if we already sent one and they don't want more...
150
-			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent'])
151
-				continue;
156
+			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent']) {
157
+							continue;
158
+			}
152 159
 			// ... or if they aren't on the bouncer's list.
153
-			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))
154
-				continue;
160
+			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only'])) {
161
+							continue;
162
+			}
155 163
 
156 164
 			// Watched topic?
157 165
 			if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member]))
@@ -161,10 +169,12 @@  discard block
 block discarded – undo
161 169
 
162 170
 				if ($type == 'reply')
163 171
 				{
164
-					if (!empty($prefs[$member]['msg_receive_body']))
165
-						$message_type .= '_body';
166
-					if (!empty($frequency))
167
-						$message_type .= '_once';
172
+					if (!empty($prefs[$member]['msg_receive_body'])) {
173
+											$message_type .= '_body';
174
+					}
175
+					if (!empty($frequency)) {
176
+											$message_type .= '_once';
177
+					}
168 178
 				}
169 179
 
170 180
 				$content_type = 'topic';
@@ -177,12 +187,14 @@  discard block
 block discarded – undo
177 187
 				$content_type = 'board';
178 188
 
179 189
 				$message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards';
180
-				if (!empty($prefs[$member]['msg_receive_body']))
181
-					$message_type .= '_body';
190
+				if (!empty($prefs[$member]['msg_receive_body'])) {
191
+									$message_type .= '_body';
192
+				}
182 193
 			}
183 194
 			// If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip
184
-			else
185
-				continue;
195
+			else {
196
+							continue;
197
+			}
186 198
 
187 199
 			// Bitwise check: Receiving a email notification?
188 200
 			if ($pref & self::RECEIVE_NOTIFY_EMAIL)
@@ -199,8 +211,9 @@  discard block
 block discarded – undo
199 211
 				$mail_result = sendmail($data['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicOptions['id'], $emaildata['is_html']);
200 212
 
201 213
 				// We failed, don't trigger a alert as we don't have a way to attempt to resend just the email currently.
202
-				if ($mail_result === false)
203
-					continue;
214
+				if ($mail_result === false) {
215
+									continue;
216
+				}
204 217
 			}
205 218
 
206 219
 			// Bitwise check: Receiving a alert?
@@ -251,14 +264,15 @@  discard block
 block discarded – undo
251 264
 		);
252 265
 
253 266
 		// Insert the alerts if any
254
-		if (!empty($alert_rows))
255
-			$smcFunc['db_insert']('',
267
+		if (!empty($alert_rows)) {
268
+					$smcFunc['db_insert']('',
256 269
 				'{db_prefix}user_alerts',
257 270
 				array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
258 271
 					'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
259 272
 				$alert_rows,
260 273
 				array()
261 274
 			);
275
+		}
262 276
 
263 277
 		return true;
264 278
 	}
@@ -269,8 +283,9 @@  discard block
 block discarded – undo
269 283
 
270 284
 		foreach ($quotedMembers as $id => $member)
271 285
 		{
272
-			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote']))
273
-				continue;
286
+			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) {
287
+							continue;
288
+			}
274 289
 
275 290
 			$done_members[] = $id;
276 291
 
@@ -324,32 +339,35 @@  discard block
 block discarded – undo
324 339
 		{
325 340
 			if (preg_match('/\[quote(.*)?\]/i', $block, $matches))
326 341
 			{
327
-				if ($quote_level == 0)
328
-					$message .= '[quote' . $matches[1] . ']';
342
+				if ($quote_level == 0) {
343
+									$message .= '[quote' . $matches[1] . ']';
344
+				}
329 345
 				$quote_level++;
330
-			}
331
-			elseif (preg_match('/\[\/quote\]/i', $block))
346
+			} elseif (preg_match('/\[\/quote\]/i', $block))
332 347
 			{
333
-				if ($quote_level <= 1)
334
-					$message .= '[/quote]';
348
+				if ($quote_level <= 1) {
349
+									$message .= '[/quote]';
350
+				}
335 351
 				if ($quote_level >= 1)
336 352
 				{
337 353
 					$quote_level--;
338 354
 					$message .= "\n";
339 355
 				}
356
+			} elseif ($quote_level <= 1) {
357
+							$message .= $block;
340 358
 			}
341
-			elseif ($quote_level <= 1)
342
-				$message .= $block;
343 359
 		}
344 360
 
345 361
 		preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches);
346 362
 
347 363
 		$id_msgs = $matches[1];
348
-		foreach ($id_msgs as $k => $id_msg)
349
-			$id_msgs[$k] = (int) $id_msg;
364
+		foreach ($id_msgs as $k => $id_msg) {
365
+					$id_msgs[$k] = (int) $id_msg;
366
+		}
350 367
 
351
-		if (empty($id_msgs))
352
-			return array();
368
+		if (empty($id_msgs)) {
369
+					return array();
370
+		}
353 371
 
354 372
 		// Get the messages
355 373
 		$request = $smcFunc['db_query']('', '
@@ -367,8 +385,9 @@  discard block
 block discarded – undo
367 385
 		$members = array();
368 386
 		while ($row = $smcFunc['db_fetch_assoc']($request))
369 387
 		{
370
-			if ($posterOptions['id'] == $row['id_member'])
371
-				continue;
388
+			if ($posterOptions['id'] == $row['id_member']) {
389
+							continue;
390
+			}
372 391
 
373 392
 			$members[$row['id_member']] = $row;
374 393
 		}
@@ -382,10 +401,11 @@  discard block
 block discarded – undo
382 401
 
383 402
 		foreach ($members as $id => $member)
384 403
 		{
385
-			if (!empty($prefs[$id]['msg_mention']))
386
-				$done_members[] = $id;
387
-			else
388
-				continue;
404
+			if (!empty($prefs[$id]['msg_mention'])) {
405
+							$done_members[] = $id;
406
+			} else {
407
+							continue;
408
+			}
389 409
 
390 410
 			// Alerts' emails are always instant
391 411
 			if ($prefs[$id]['msg_mention'] & self::RECEIVE_NOTIFY_EMAIL)
Please login to merge, or discard this patch.