Completed
Push — master ( 88acae...8817c3 )
by Jacob
03:16
created
script/cron/build-activity-stream.php 1 patch
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -11,58 +11,58 @@  discard block
 block discarded – undo
11 11
 
12 12
 $lastBlogActivity = $activityRepository->getActivityLastUpdateByType('blog');
13 13
 if ($lastBlogActivity === false) {
14
-    $lastBlogActivityDateTime = new DateTime('2008-05-03');
14
+	$lastBlogActivityDateTime = new DateTime('2008-05-03');
15 15
 } else {
16
-    $lastBlogActivityDateTime = new DateTime($lastBlogActivity['updated_at']);
17
-    $lastBlogActivityDateTime->modify('-5 days');
16
+	$lastBlogActivityDateTime = new DateTime($lastBlogActivity['updated_at']);
17
+	$lastBlogActivityDateTime->modify('-5 days');
18 18
 }
19 19
 $newBlogActivity = $blogRepository->getBlogsUpdatedSince($lastBlogActivityDateTime);
20 20
 foreach ($newBlogActivity as $blog) {
21
-    $uniqueBlogCheck = $activityRepository->getActivityByTypeId('blog', $blog['id']);
22
-    if ($uniqueBlogCheck !== false) {
23
-        continue;
24
-    }
25
-
26
-    $blogData = json_decode($blog['metadata'], true);
27
-    $message = sprintf(
28
-        'Blogged about %s | %s.',
29
-        str_replace('-', ' ', $blogData['category']),
30
-        $blogData['title']
31
-    );
32
-
33
-    if (isset($blogData['enclosure'])) {
34
-        $messageLong = sprintf(
35
-            "<img src=\"%s\" alt=\"Blog | %s\" />\n" .
36
-            "<h4><a href=\"%s\" title=\"Jacob Emerick's Blog | %s\">%s</a></h4>\n" .
37
-            "<p>%s [<a href=\"%s\">read more</a></a>]</p>",
38
-            $blogData['enclosure']['@attributes']['url'],
39
-            $blogData['title'],
40
-            $blogData['link'],
41
-            $blogData['title'],
42
-            $blogData['title'],
43
-            htmlentities($blogData['description']),
44
-            $blogData['link']
45
-        );
46
-    } else {
47
-        $messageLong = sprintf(
48
-            "<h4><a href=\"%s\" title=\"Jacob Emerick's Blog | %s\">%s</a></h4>\n" .
49
-            "<p>%s [<a href=\"%s\">read more</a></a>]</p>",
50
-            $blogData['link'],
51
-            $blogData['title'],
52
-            $blogData['title'],
53
-            htmlentities($blogData['description']),
54
-            $blogData['link']
55
-        );
56
-    }
57
-
58
-    $activityRepository->insertActivity(
59
-        $message,
60
-        $messageLong,
61
-        (new DateTime($blog['datetime'])),
62
-        [],
63
-        'blog',
64
-        $blog['id']
65
-    );
21
+	$uniqueBlogCheck = $activityRepository->getActivityByTypeId('blog', $blog['id']);
22
+	if ($uniqueBlogCheck !== false) {
23
+		continue;
24
+	}
25
+
26
+	$blogData = json_decode($blog['metadata'], true);
27
+	$message = sprintf(
28
+		'Blogged about %s | %s.',
29
+		str_replace('-', ' ', $blogData['category']),
30
+		$blogData['title']
31
+	);
32
+
33
+	if (isset($blogData['enclosure'])) {
34
+		$messageLong = sprintf(
35
+			"<img src=\"%s\" alt=\"Blog | %s\" />\n" .
36
+			"<h4><a href=\"%s\" title=\"Jacob Emerick's Blog | %s\">%s</a></h4>\n" .
37
+			"<p>%s [<a href=\"%s\">read more</a></a>]</p>",
38
+			$blogData['enclosure']['@attributes']['url'],
39
+			$blogData['title'],
40
+			$blogData['link'],
41
+			$blogData['title'],
42
+			$blogData['title'],
43
+			htmlentities($blogData['description']),
44
+			$blogData['link']
45
+		);
46
+	} else {
47
+		$messageLong = sprintf(
48
+			"<h4><a href=\"%s\" title=\"Jacob Emerick's Blog | %s\">%s</a></h4>\n" .
49
+			"<p>%s [<a href=\"%s\">read more</a></a>]</p>",
50
+			$blogData['link'],
51
+			$blogData['title'],
52
+			$blogData['title'],
53
+			htmlentities($blogData['description']),
54
+			$blogData['link']
55
+		);
56
+	}
57
+
58
+	$activityRepository->insertActivity(
59
+		$message,
60
+		$messageLong,
61
+		(new DateTime($blog['datetime'])),
62
+		[],
63
+		'blog',
64
+		$blog['id']
65
+	);
66 66
 }
67 67
 
68 68
 use Jacobemerick\Web\Domain\Stream\BlogComment\MysqlBlogCommentRepository as BlogCommentRepository;
@@ -70,30 +70,30 @@  discard block
 block discarded – undo
70 70
 $blogCommentActivity = $blogCommentRepository->getBlogComments();
71 71
 $blogCommentHolder = [];
72 72
 foreach ($blogCommentActivity as $blogComment) {
73
-    $blogPermalink = $blogComment['permalink'];
74
-    $blogPermalink = explode('#', $blogPermalink);
75
-    $blogPermalink = current($blogPermalink);
76
-
77
-    $blog = $blogRepository->getBlogByPermalink($blogPermalink);
78
-    if (!array_key_exists($blog['id'], $blogCommentHolder)) {
79
-        $blogCommentHolder[$blog['id']] = 1;
80
-    } else {
81
-        $blogCommentHolder[$blog['id']]++;
82
-    }
73
+	$blogPermalink = $blogComment['permalink'];
74
+	$blogPermalink = explode('#', $blogPermalink);
75
+	$blogPermalink = current($blogPermalink);
76
+
77
+	$blog = $blogRepository->getBlogByPermalink($blogPermalink);
78
+	if (!array_key_exists($blog['id'], $blogCommentHolder)) {
79
+		$blogCommentHolder[$blog['id']] = 1;
80
+	} else {
81
+		$blogCommentHolder[$blog['id']]++;
82
+	}
83 83
 }
84 84
 
85 85
 foreach ($blogCommentHolder as $blogId => $commentCount) {
86
-    $blogActivity = $activityRepository->getActivityByTypeId('blog', $blogId);
87
-    $blogActivityMetadata = json_decode($blogActivity['metadata'], true);
88
-    if (
89
-        !isset($blogActivityMetadata['comments']) ||
90
-        $blogActivityMetadata['comments'] != $commentCount
91
-    ) {
92
-        $activityRepository->updateActivityMetadata(
93
-            $blogActivity['id'],
94
-            ['comments' => $commentCount]
95
-        );
96
-    }
86
+	$blogActivity = $activityRepository->getActivityByTypeId('blog', $blogId);
87
+	$blogActivityMetadata = json_decode($blogActivity['metadata'], true);
88
+	if (
89
+		!isset($blogActivityMetadata['comments']) ||
90
+		$blogActivityMetadata['comments'] != $commentCount
91
+	) {
92
+		$activityRepository->updateActivityMetadata(
93
+			$blogActivity['id'],
94
+			['comments' => $commentCount]
95
+		);
96
+	}
97 97
 }
98 98
 
99 99
 // distance
@@ -102,67 +102,67 @@  discard block
 block discarded – undo
102 102
 
103 103
 $lastDailyMileActivity = $activityRepository->getActivityLastUpdateByType('distance');
104 104
 if ($lastDailyMileActivity === false) {
105
-    $lastDailyMileActivityDateTime = new DateTime('2008-05-03');
105
+	$lastDailyMileActivityDateTime = new DateTime('2008-05-03');
106 106
 } else {
107
-    $lastDailyMileActivityDateTime = new DateTime($lastDailyMileActivity['updated_at']);
108
-    $lastDailyMileActivityDateTime->modify('-5 days');
107
+	$lastDailyMileActivityDateTime = new DateTime($lastDailyMileActivity['updated_at']);
108
+	$lastDailyMileActivityDateTime->modify('-5 days');
109 109
 }
110 110
 $newDailyMileActivity = $dailyMileRepository->getDailyMilesUpdatedSince($lastDailyMileActivityDateTime);
111 111
 foreach ($newDailyMileActivity as $dailyMile) {
112
-    $uniqueDailyMileCheck = $activityRepository->getActivityByTypeId('distance', $dailyMile['id']);
113
-    if ($uniqueDailyMileCheck !== false) {
114
-        continue;
115
-    }
116
-
117
-    $dailyMileData = json_decode($dailyMile['metadata'], true);
118
-    if ($dailyMile['type'] == 'Hiking') {
119
-        $message = sprintf(
120
-            '%s %.2f %s and felt %s.',
121
-            'Hiked',
122
-            $dailyMileData['workout']['distance']['value'],
123
-            $dailyMileData['workout']['distance']['units'],
124
-            $dailyMileData['workout']['felt']
125
-        );
126
-        $messageLong = "<p>{$message}</p>";
127
-        if (isset($dailyMileData['workout']['title'])) {
128
-            $messageLong .= "\n<p>I was hiking up around the {$dailyMileData['workout']['title']} area.</p>";
129
-        }
130
-    } else if ($dailyMile['type'] == 'Running') {
131
-        $message = sprintf(
132
-            '%s %.2f %s and felt %s.',
133
-            'Ran',
134
-            $dailyMileData['workout']['distance']['value'],
135
-            $dailyMileData['workout']['distance']['units'],
136
-            $dailyMileData['workout']['felt']
137
-        );
138
-        $messageLong = "<p>{$message}</p>";
139
-        if (isset($dailyMileData['message'])) {
140
-            $messageLong .= "\n<p>Afterwards, I was all like '{$dailyMileData['message']}'.</p>";
141
-        }
142
-    } else if ($dailyMile['type'] == 'Walking') {
143
-        $message = sprintf(
144
-            '%s %.2f %s and felt %s.',
145
-            'Walked',
146
-            $dailyMileData['workout']['distance']['value'],
147
-            $dailyMileData['workout']['distance']['units'],
148
-            $dailyMileData['workout']['felt']
149
-        );
150
-        $messageLong = "<p>{$message}</p>";
151
-        if (isset($dailyMileData['message'])) {
152
-            $messageLong .= "\n<p>{$dailyMileData['message']}</p>";
153
-        }
154
-    } else {
155
-        continue;
156
-    }
157
-
158
-    $activityRepository->insertActivity(
159
-        $message,
160
-        $messageLong,
161
-        (new DateTime($dailyMile['datetime'])),
162
-        [],
163
-        'distance',
164
-        $dailyMile['id']
165
-    );
112
+	$uniqueDailyMileCheck = $activityRepository->getActivityByTypeId('distance', $dailyMile['id']);
113
+	if ($uniqueDailyMileCheck !== false) {
114
+		continue;
115
+	}
116
+
117
+	$dailyMileData = json_decode($dailyMile['metadata'], true);
118
+	if ($dailyMile['type'] == 'Hiking') {
119
+		$message = sprintf(
120
+			'%s %.2f %s and felt %s.',
121
+			'Hiked',
122
+			$dailyMileData['workout']['distance']['value'],
123
+			$dailyMileData['workout']['distance']['units'],
124
+			$dailyMileData['workout']['felt']
125
+		);
126
+		$messageLong = "<p>{$message}</p>";
127
+		if (isset($dailyMileData['workout']['title'])) {
128
+			$messageLong .= "\n<p>I was hiking up around the {$dailyMileData['workout']['title']} area.</p>";
129
+		}
130
+	} else if ($dailyMile['type'] == 'Running') {
131
+		$message = sprintf(
132
+			'%s %.2f %s and felt %s.',
133
+			'Ran',
134
+			$dailyMileData['workout']['distance']['value'],
135
+			$dailyMileData['workout']['distance']['units'],
136
+			$dailyMileData['workout']['felt']
137
+		);
138
+		$messageLong = "<p>{$message}</p>";
139
+		if (isset($dailyMileData['message'])) {
140
+			$messageLong .= "\n<p>Afterwards, I was all like '{$dailyMileData['message']}'.</p>";
141
+		}
142
+	} else if ($dailyMile['type'] == 'Walking') {
143
+		$message = sprintf(
144
+			'%s %.2f %s and felt %s.',
145
+			'Walked',
146
+			$dailyMileData['workout']['distance']['value'],
147
+			$dailyMileData['workout']['distance']['units'],
148
+			$dailyMileData['workout']['felt']
149
+		);
150
+		$messageLong = "<p>{$message}</p>";
151
+		if (isset($dailyMileData['message'])) {
152
+			$messageLong .= "\n<p>{$dailyMileData['message']}</p>";
153
+		}
154
+	} else {
155
+		continue;
156
+	}
157
+
158
+	$activityRepository->insertActivity(
159
+		$message,
160
+		$messageLong,
161
+		(new DateTime($dailyMile['datetime'])),
162
+		[],
163
+		'distance',
164
+		$dailyMile['id']
165
+	);
166 166
 }
167 167
 
168 168
 // github
@@ -171,128 +171,128 @@  discard block
 block discarded – undo
171 171
 
172 172
 $lastGithubActivity = $activityRepository->getActivityLastUpdateByType('github');
173 173
 if ($lastGithubActivity === false) {
174
-    $lastGithubActivityDateTime = new DateTime('2015-10-01');
174
+	$lastGithubActivityDateTime = new DateTime('2015-10-01');
175 175
 } else {
176
-    $lastGithubActivityDateTime = new DateTime($lastGithubActivity['updated_at']);
177
-    $lastGithubActivityDateTime->modify('-5 days');
176
+	$lastGithubActivityDateTime = new DateTime($lastGithubActivity['updated_at']);
177
+	$lastGithubActivityDateTime->modify('-5 days');
178 178
 }
179 179
 
180 180
 $newGithubActivity = $githubRepository->getGithubsUpdatedSince($lastGithubActivityDateTime);
181 181
 foreach ($newGithubActivity as $github) {
182
-    $uniqueGithubCheck = $activityRepository->getActivityByTypeId('github', $github['id']);
183
-    if ($uniqueGithubCheck !== false) {
184
-        continue;
185
-    }
186
-
187
-    $githubData = json_decode($github['metadata'], true);
188
-
189
-    if ($github['type'] == 'CreateEvent') {
190
-        if (
191
-            $githubData['payload']['ref_type'] == 'branch' ||
192
-            $githubData['payload']['ref_type'] == 'tag'
193
-        ) {
194
-            $message = sprintf(
195
-                'Created %s %s at %s.',
196
-                $githubData['payload']['ref_type'],
197
-                $githubData['payload']['ref'],
198
-                $githubData['repo']['name']
199
-            );
200
-            $messageLong = sprintf(
201
-                '<p>Created %s %s at <a href="%s" target="_blank" title="Github | %s">%s</a>.</p>',
202
-                $githubData['payload']['ref_type'],
203
-                $githubData['payload']['ref'],
204
-                "https://github.com/{$githubData['repo']['name']}",
205
-                $githubData['repo']['name'],
206
-                $githubData['repo']['name']
207
-            );
208
-        } else if ($githubData['payload']['ref_type'] == 'repository') {
209
-            $message = sprintf(
210
-                'Created %s %s.',
211
-                $githubData['payload']['ref_type'],
212
-                $githubData['repo']['name']
213
-            );
214
-            $messageLong = sprintf(
215
-                '<p>Created %s <a href="%s" target="_blank" title="Github | %s">%s</a>.</p>',
216
-                $githubData['payload']['ref_type'],
217
-                "https://github.com/{$githubData['repo']['name']}",
218
-                $githubData['repo']['name'],
219
-                $githubData['repo']['name']
220
-            );
221
-        } else {
222
-            continue;
223
-        }
224
-    } else if ($github['type'] == 'ForkEvent') {
225
-        $message = sprintf(
226
-            'Forked %s to %s',
227
-            $githubData['repo']['name'],
228
-            $githubData['payload']['forkee']['full_name']
229
-        );
230
-        $messageLong = sprintf(
231
-            '<p>Forked <a href="%s" target="_blank" title="Github | %s">%s</a> to <a href="%s" target="_blank" title="Github | %s">%s</a>.',
232
-            "https://github.com/{$githubData['repo']['name']}",
233
-            $githubData['repo']['name'],
234
-            $githubData['repo']['name'],
235
-            $githubData['payload']['forkee']['html_url'],
236
-            $githubData['payload']['forkee']['full_name'],
237
-            $githubData['payload']['forkee']['full_name']
238
-        );
239
-    } else if ($github['type'] == 'PullRequestEvent') {
240
-        $message = sprintf(
241
-            '%s a pull request at %s',
242
-            ucwords($githubData['payload']['action']),
243
-            $githubData['repo']['name']
244
-        );
245
-        $messageLong = sprintf(
246
-            '<p>%s pull request <a href="%s" target="_blank" title="Github | %s PR %d">%d</a> at <a href="%s" target="_blank" title="Github | %s">%s</a>.</p>',
247
-            ucwords($githubData['payload']['action']),
248
-            $githubData['payload']['pull_request']['html_url'],
249
-            $githubData['repo']['name'],
250
-            $githubData['payload']['number'],
251
-            $githubData['payload']['number'],
252
-            "https://github.com/{$githubData['repo']['name']}",
253
-            $githubData['repo']['name'],
254
-            $githubData['repo']['name']
255
-        );
256
-    } else if ($github['type'] == 'PushEvent') {
257
-        $message = sprintf(
258
-            'Pushed some code at %s.',
259
-            $githubData['repo']['name']
260
-        );
261
-        $messageLong = sprintf(
262
-            "<p>Pushed some code at <a href=\"%s\" target=\"_blank\" title=\"Github | %s\">%s</a>.</p>\n",
263
-            $githubData['payload']['ref'],
264
-            "https://github.com/{$githubData['repo']['name']}",
265
-            $githubData['repo']['name'],
266
-            $githubData['repo']['name']
267
-        );
268
-        $messageLong .= "<ul>\n";
269
-        foreach ($githubData['payload']['commits'] as $commit) {
270
-            $messageShort = $commit['message'];
271
-            $messageShort = strtok($messageShort, "\n");
272
-            if (strlen($messageShort) > 72) {
273
-                $messageShort = wordwrap($messageShort, 65);
274
-                $messageShort = strtok($messageShort, "\n");
275
-                $messageShort .= '...';
276
-            }
277
-            $messageLong .= sprintf(
278
-                "<li><a href=\"%s\" target=\"_blank\" title=\"Github | %s\">%s</a> %s.</li>\n",
279
-                "https://github.com/{$githubData['repo']['name']}/commit/{$commit['sha']}",
280
-                substr($commit['sha'], 0, 7),
281
-                substr($commit['sha'], 0, 7),
282
-                $messageShort
283
-            );
284
-        }
285
-        $messageLong .= "</ul>";
286
-    }
287
-
288
-    $activityRepository->insertActivity(
289
-        $message,
290
-        $messageLong,
291
-        (new DateTime($github['datetime'])),
292
-        [],
293
-        'github',
294
-        $github['id']
295
-    );
182
+	$uniqueGithubCheck = $activityRepository->getActivityByTypeId('github', $github['id']);
183
+	if ($uniqueGithubCheck !== false) {
184
+		continue;
185
+	}
186
+
187
+	$githubData = json_decode($github['metadata'], true);
188
+
189
+	if ($github['type'] == 'CreateEvent') {
190
+		if (
191
+			$githubData['payload']['ref_type'] == 'branch' ||
192
+			$githubData['payload']['ref_type'] == 'tag'
193
+		) {
194
+			$message = sprintf(
195
+				'Created %s %s at %s.',
196
+				$githubData['payload']['ref_type'],
197
+				$githubData['payload']['ref'],
198
+				$githubData['repo']['name']
199
+			);
200
+			$messageLong = sprintf(
201
+				'<p>Created %s %s at <a href="%s" target="_blank" title="Github | %s">%s</a>.</p>',
202
+				$githubData['payload']['ref_type'],
203
+				$githubData['payload']['ref'],
204
+				"https://github.com/{$githubData['repo']['name']}",
205
+				$githubData['repo']['name'],
206
+				$githubData['repo']['name']
207
+			);
208
+		} else if ($githubData['payload']['ref_type'] == 'repository') {
209
+			$message = sprintf(
210
+				'Created %s %s.',
211
+				$githubData['payload']['ref_type'],
212
+				$githubData['repo']['name']
213
+			);
214
+			$messageLong = sprintf(
215
+				'<p>Created %s <a href="%s" target="_blank" title="Github | %s">%s</a>.</p>',
216
+				$githubData['payload']['ref_type'],
217
+				"https://github.com/{$githubData['repo']['name']}",
218
+				$githubData['repo']['name'],
219
+				$githubData['repo']['name']
220
+			);
221
+		} else {
222
+			continue;
223
+		}
224
+	} else if ($github['type'] == 'ForkEvent') {
225
+		$message = sprintf(
226
+			'Forked %s to %s',
227
+			$githubData['repo']['name'],
228
+			$githubData['payload']['forkee']['full_name']
229
+		);
230
+		$messageLong = sprintf(
231
+			'<p>Forked <a href="%s" target="_blank" title="Github | %s">%s</a> to <a href="%s" target="_blank" title="Github | %s">%s</a>.',
232
+			"https://github.com/{$githubData['repo']['name']}",
233
+			$githubData['repo']['name'],
234
+			$githubData['repo']['name'],
235
+			$githubData['payload']['forkee']['html_url'],
236
+			$githubData['payload']['forkee']['full_name'],
237
+			$githubData['payload']['forkee']['full_name']
238
+		);
239
+	} else if ($github['type'] == 'PullRequestEvent') {
240
+		$message = sprintf(
241
+			'%s a pull request at %s',
242
+			ucwords($githubData['payload']['action']),
243
+			$githubData['repo']['name']
244
+		);
245
+		$messageLong = sprintf(
246
+			'<p>%s pull request <a href="%s" target="_blank" title="Github | %s PR %d">%d</a> at <a href="%s" target="_blank" title="Github | %s">%s</a>.</p>',
247
+			ucwords($githubData['payload']['action']),
248
+			$githubData['payload']['pull_request']['html_url'],
249
+			$githubData['repo']['name'],
250
+			$githubData['payload']['number'],
251
+			$githubData['payload']['number'],
252
+			"https://github.com/{$githubData['repo']['name']}",
253
+			$githubData['repo']['name'],
254
+			$githubData['repo']['name']
255
+		);
256
+	} else if ($github['type'] == 'PushEvent') {
257
+		$message = sprintf(
258
+			'Pushed some code at %s.',
259
+			$githubData['repo']['name']
260
+		);
261
+		$messageLong = sprintf(
262
+			"<p>Pushed some code at <a href=\"%s\" target=\"_blank\" title=\"Github | %s\">%s</a>.</p>\n",
263
+			$githubData['payload']['ref'],
264
+			"https://github.com/{$githubData['repo']['name']}",
265
+			$githubData['repo']['name'],
266
+			$githubData['repo']['name']
267
+		);
268
+		$messageLong .= "<ul>\n";
269
+		foreach ($githubData['payload']['commits'] as $commit) {
270
+			$messageShort = $commit['message'];
271
+			$messageShort = strtok($messageShort, "\n");
272
+			if (strlen($messageShort) > 72) {
273
+				$messageShort = wordwrap($messageShort, 65);
274
+				$messageShort = strtok($messageShort, "\n");
275
+				$messageShort .= '...';
276
+			}
277
+			$messageLong .= sprintf(
278
+				"<li><a href=\"%s\" target=\"_blank\" title=\"Github | %s\">%s</a> %s.</li>\n",
279
+				"https://github.com/{$githubData['repo']['name']}/commit/{$commit['sha']}",
280
+				substr($commit['sha'], 0, 7),
281
+				substr($commit['sha'], 0, 7),
282
+				$messageShort
283
+			);
284
+		}
285
+		$messageLong .= "</ul>";
286
+	}
287
+
288
+	$activityRepository->insertActivity(
289
+		$message,
290
+		$messageLong,
291
+		(new DateTime($github['datetime'])),
292
+		[],
293
+		'github',
294
+		$github['id']
295
+	);
296 296
 }
297 297
 
298 298
 // books
@@ -301,46 +301,46 @@  discard block
 block discarded – undo
301 301
 
302 302
 $lastGoodreadActivity = $activityRepository->getActivityLastUpdateByType('book');
303 303
 if ($lastGoodreadActivity === false) {
304
-    $lastGoodreadActivityDateTime = new DateTime('2010-08-28');
304
+	$lastGoodreadActivityDateTime = new DateTime('2010-08-28');
305 305
 } else {
306
-    $lastGoodreadActivityDateTime = new DateTime($lastGoodreadActivity['updated_at']);
307
-    $lastGoodreadActivityDateTime->modify('-5 days');
306
+	$lastGoodreadActivityDateTime = new DateTime($lastGoodreadActivity['updated_at']);
307
+	$lastGoodreadActivityDateTime->modify('-5 days');
308 308
 }
309 309
 $newGoodreadActivity = $goodreadRepository->getGoodreadsUpdatedSince($lastGoodreadActivityDateTime);
310 310
 foreach ($newGoodreadActivity as $goodread) {
311
-    $uniqueGoodreadCheck = $activityRepository->getActivityByTypeId('book', $goodread['id']);
312
-    if ($uniqueGoodreadCheck !== false) {
313
-        continue;
314
-    }
315
-
316
-    $goodreadData = json_decode($goodread['metadata'], true);
317
-
318
-    if (empty($goodreadData['user_read_at'])) {
319
-        continue;
320
-    }
321
-
322
-    $message = sprintf(
323
-        'Read %s by %s.',
324
-        $goodreadData['title'],
325
-        $goodreadData['author_name']
326
-    );
327
-    if (isset($goodreadData['book_large_image_url'])) {
328
-        $messageLong = sprintf(
329
-            "<img alt=\"Goodreads | %s\" src=\"%s\" />\n",
330
-            $goodreadData['title'],
331
-            str_replace('http', 'https', $goodreadData['book_large_image_url'])
332
-        );
333
-    }
334
-    $messageLong .= "<p>{$message}</p>";
335
-
336
-    $activityRepository->insertActivity(
337
-        $message,
338
-        $messageLong,
339
-        (new DateTime($goodread['datetime'])),
340
-        [],
341
-        'book',
342
-        $goodread['id']
343
-    );
311
+	$uniqueGoodreadCheck = $activityRepository->getActivityByTypeId('book', $goodread['id']);
312
+	if ($uniqueGoodreadCheck !== false) {
313
+		continue;
314
+	}
315
+
316
+	$goodreadData = json_decode($goodread['metadata'], true);
317
+
318
+	if (empty($goodreadData['user_read_at'])) {
319
+		continue;
320
+	}
321
+
322
+	$message = sprintf(
323
+		'Read %s by %s.',
324
+		$goodreadData['title'],
325
+		$goodreadData['author_name']
326
+	);
327
+	if (isset($goodreadData['book_large_image_url'])) {
328
+		$messageLong = sprintf(
329
+			"<img alt=\"Goodreads | %s\" src=\"%s\" />\n",
330
+			$goodreadData['title'],
331
+			str_replace('http', 'https', $goodreadData['book_large_image_url'])
332
+		);
333
+	}
334
+	$messageLong .= "<p>{$message}</p>";
335
+
336
+	$activityRepository->insertActivity(
337
+		$message,
338
+		$messageLong,
339
+		(new DateTime($goodread['datetime'])),
340
+		[],
341
+		'book',
342
+		$goodread['id']
343
+	);
344 344
 }
345 345
 
346 346
 // twitter
@@ -349,136 +349,136 @@  discard block
 block discarded – undo
349 349
 
350 350
 $lastTwitterActivity = $activityRepository->getActivityLastUpdateByType('twitter');
351 351
 if ($lastTwitterActivity === false) {
352
-    $lastTwitterActivityDateTime = new DateTime('2010-03-10');
352
+	$lastTwitterActivityDateTime = new DateTime('2010-03-10');
353 353
 } else {
354
-    $lastTwitterActivityDateTime = new DateTime($lastTwitterActivity['updated_at']);
355
-    $lastTwitterActivityDateTime->modify('-5 days');
354
+	$lastTwitterActivityDateTime = new DateTime($lastTwitterActivity['updated_at']);
355
+	$lastTwitterActivityDateTime->modify('-5 days');
356 356
 }
357 357
 $newTwitterActivity = $twitterRepository->getTwittersUpdatedSince($lastTwitterActivityDateTime);
358 358
 foreach ($newTwitterActivity as $twitter) {
359
-    $twitterData = json_decode($twitter['metadata'], true);
360
-
361
-    $uniqueTwitterCheck = $activityRepository->getActivityByTypeId('twitter', $twitter['id']);
362
-    if ($uniqueTwitterCheck !== false) {
363
-        $metadata = [];
364
-        if ($twitterData['favorite_count'] > 0) {
365
-            $metadata['favorites'] = $twitterData['favorite_count'];
366
-        }
367
-        if ($twitterData['retweet_count'] > 0) {
368
-            $metadata['retweets'] = $twitterData['retweet_count'];
369
-        }
370
-
371
-        $activityRepository->updateActivityMetadata($uniqueTwitterCheck['id'], $metadata);
372
-        continue;
373
-    }
374
-
375
-    if (
376
-        ($twitterData['in_reply_to_user_id'] != null || substr($twitterData['text'], 0, 1) === '@') &&
377
-        $twitterData['favorite_count'] == 0 &&
378
-        $twitterData['retweet_count'] == 0
379
-    ) {
380
-        continue;
381
-    }
382
-
383
-    $entityHolder = [];
384
-    foreach ($twitterData['entities'] as $entityType => $entities) {
385
-        foreach ($entities as $entity) {
386
-            if ($entityType == 'urls' || $entityType == 'media') {
387
-                $entityHolder[$entity['indices'][0]] = [
388
-                    'start' => $entity['indices'][0],
389
-                    'end' => $entity['indices'][1],
390
-                    'replace' => "[{$entity['display_url']}]"
391
-                ];
392
-            }
393
-        }
394
-    }
395
-
396
-    $message = $twitterData['text'];
397
-    krsort($entityHolder);
398
-    foreach($entityHolder as $entity)
399
-    {
400
-        $message =
401
-            mb_substr($message, 0, $entity['start']) .
402
-            $entity['replace'] .
403
-            mb_substr($message, $entity['end'], null, 'UTF-8');
404
-    }
405
-    $message = mb_convert_encoding($message, 'HTML-ENTITIES', 'UTF-8');
406
-    $message = trim(preg_replace('/\s+/', ' ', $message));
407
-    $message = "Tweeted | {$message}";
408
-
409
-    $entityHolder = [];
410
-    foreach ($twitterData['entities'] as $entityType => $entities) {
411
-        foreach ($entities as $entity) {
412
-            if ($entityType == 'hashtags') {
413
-                $replace = sprintf(
414
-                    '<a href="https://twitter.com/search?q=%%23%s&src=hash" rel="nofollow" target="_blank">#%s</a>',
415
-                    $entity['text'],
416
-                    $entity['text']
417
-                );
418
-            } else if ($entityType == 'urls') {
419
-                $replace = sprintf(
420
-                    '<a href="%s" rel="nofollow" target="_blank" title="%s">%s</a>',
421
-                    $entity['url'],
422
-                    $entity['expanded_url'],
423
-                    $entity['display_url']
424
-                );
425
-            } else if ($entityType == 'user_mentions') {
426
-                $replace = sprintf(
427
-                    '<a href="https://twitter.com/%s" rel="nofollow" target="_blank" title="Twitter | %s">@%s</a>',
428
-                    strtolower($entity['screen_name']),
429
-                    $entity['name'],
430
-                    $entity['screen_name']
431
-                );
432
-            } else if ($entityType == 'media') {
433
-                $replace = sprintf(
434
-                    "<img src=\"%s:%s\" alt=\"%s\" height=\"%s\" width=\"%s\" />",
435
-                    $entity['media_url_https'],
436
-                    'large',
437
-                    $entity['display_url'],
438
-                    $entity['sizes']['large']['h'],
439
-                    $entity['sizes']['large']['w']
440
-                );
441
-            } else {
442
-                continue 2;
443
-            }
444
-
445
-            $entityHolder[$entity['indices'][0]] = [
446
-                'start' => $entity['indices'][0],
447
-                'end' => $entity['indices'][1],
448
-                'replace' => $replace,
449
-            ];
450
-        }
451
-    }
452
-
453
-    $messageLong = $twitterData['text'];
454
-    krsort($entityHolder);
455
-    foreach($entityHolder as $entity)
456
-    {
457
-        $messageLong =
458
-            mb_substr($messageLong, 0, $entity['start']) .
459
-            $entity['replace'] .
460
-            mb_substr($messageLong, $entity['end'], null, 'UTF-8');
461
-    }
462
-    $messageLong = mb_convert_encoding($messageLong, 'HTML-ENTITIES', 'UTF-8');
463
-    $messageLong = nl2br($messageLong, true);
464
-    $messageLong = "<p>{$messageLong}</p>";
465
-
466
-    $metadata = [];
467
-    if ($twitterData['favorite_count'] > 0) {
468
-        $metadata['favorites'] = $twitterData['favorite_count'];
469
-    }
470
-    if ($twitterData['retweet_count'] > 0) {
471
-        $metadata['retweets'] = $twitterData['retweet_count'];
472
-    }
473
-
474
-    $activityRepository->insertActivity(
475
-        $message,
476
-        $messageLong,
477
-        (new DateTime($twitter['datetime'])),
478
-        $metadata,
479
-        'twitter',
480
-        $twitter['id']
481
-    );
359
+	$twitterData = json_decode($twitter['metadata'], true);
360
+
361
+	$uniqueTwitterCheck = $activityRepository->getActivityByTypeId('twitter', $twitter['id']);
362
+	if ($uniqueTwitterCheck !== false) {
363
+		$metadata = [];
364
+		if ($twitterData['favorite_count'] > 0) {
365
+			$metadata['favorites'] = $twitterData['favorite_count'];
366
+		}
367
+		if ($twitterData['retweet_count'] > 0) {
368
+			$metadata['retweets'] = $twitterData['retweet_count'];
369
+		}
370
+
371
+		$activityRepository->updateActivityMetadata($uniqueTwitterCheck['id'], $metadata);
372
+		continue;
373
+	}
374
+
375
+	if (
376
+		($twitterData['in_reply_to_user_id'] != null || substr($twitterData['text'], 0, 1) === '@') &&
377
+		$twitterData['favorite_count'] == 0 &&
378
+		$twitterData['retweet_count'] == 0
379
+	) {
380
+		continue;
381
+	}
382
+
383
+	$entityHolder = [];
384
+	foreach ($twitterData['entities'] as $entityType => $entities) {
385
+		foreach ($entities as $entity) {
386
+			if ($entityType == 'urls' || $entityType == 'media') {
387
+				$entityHolder[$entity['indices'][0]] = [
388
+					'start' => $entity['indices'][0],
389
+					'end' => $entity['indices'][1],
390
+					'replace' => "[{$entity['display_url']}]"
391
+				];
392
+			}
393
+		}
394
+	}
395
+
396
+	$message = $twitterData['text'];
397
+	krsort($entityHolder);
398
+	foreach($entityHolder as $entity)
399
+	{
400
+		$message =
401
+			mb_substr($message, 0, $entity['start']) .
402
+			$entity['replace'] .
403
+			mb_substr($message, $entity['end'], null, 'UTF-8');
404
+	}
405
+	$message = mb_convert_encoding($message, 'HTML-ENTITIES', 'UTF-8');
406
+	$message = trim(preg_replace('/\s+/', ' ', $message));
407
+	$message = "Tweeted | {$message}";
408
+
409
+	$entityHolder = [];
410
+	foreach ($twitterData['entities'] as $entityType => $entities) {
411
+		foreach ($entities as $entity) {
412
+			if ($entityType == 'hashtags') {
413
+				$replace = sprintf(
414
+					'<a href="https://twitter.com/search?q=%%23%s&src=hash" rel="nofollow" target="_blank">#%s</a>',
415
+					$entity['text'],
416
+					$entity['text']
417
+				);
418
+			} else if ($entityType == 'urls') {
419
+				$replace = sprintf(
420
+					'<a href="%s" rel="nofollow" target="_blank" title="%s">%s</a>',
421
+					$entity['url'],
422
+					$entity['expanded_url'],
423
+					$entity['display_url']
424
+				);
425
+			} else if ($entityType == 'user_mentions') {
426
+				$replace = sprintf(
427
+					'<a href="https://twitter.com/%s" rel="nofollow" target="_blank" title="Twitter | %s">@%s</a>',
428
+					strtolower($entity['screen_name']),
429
+					$entity['name'],
430
+					$entity['screen_name']
431
+				);
432
+			} else if ($entityType == 'media') {
433
+				$replace = sprintf(
434
+					"<img src=\"%s:%s\" alt=\"%s\" height=\"%s\" width=\"%s\" />",
435
+					$entity['media_url_https'],
436
+					'large',
437
+					$entity['display_url'],
438
+					$entity['sizes']['large']['h'],
439
+					$entity['sizes']['large']['w']
440
+				);
441
+			} else {
442
+				continue 2;
443
+			}
444
+
445
+			$entityHolder[$entity['indices'][0]] = [
446
+				'start' => $entity['indices'][0],
447
+				'end' => $entity['indices'][1],
448
+				'replace' => $replace,
449
+			];
450
+		}
451
+	}
452
+
453
+	$messageLong = $twitterData['text'];
454
+	krsort($entityHolder);
455
+	foreach($entityHolder as $entity)
456
+	{
457
+		$messageLong =
458
+			mb_substr($messageLong, 0, $entity['start']) .
459
+			$entity['replace'] .
460
+			mb_substr($messageLong, $entity['end'], null, 'UTF-8');
461
+	}
462
+	$messageLong = mb_convert_encoding($messageLong, 'HTML-ENTITIES', 'UTF-8');
463
+	$messageLong = nl2br($messageLong, true);
464
+	$messageLong = "<p>{$messageLong}</p>";
465
+
466
+	$metadata = [];
467
+	if ($twitterData['favorite_count'] > 0) {
468
+		$metadata['favorites'] = $twitterData['favorite_count'];
469
+	}
470
+	if ($twitterData['retweet_count'] > 0) {
471
+		$metadata['retweets'] = $twitterData['retweet_count'];
472
+	}
473
+
474
+	$activityRepository->insertActivity(
475
+		$message,
476
+		$messageLong,
477
+		(new DateTime($twitter['datetime'])),
478
+		$metadata,
479
+		'twitter',
480
+		$twitter['id']
481
+	);
482 482
 }
483 483
 
484 484
 // youtube
@@ -487,39 +487,39 @@  discard block
 block discarded – undo
487 487
 
488 488
 $lastYouTubeActivity = $activityRepository->getActivityLastUpdateByType('youtube');
489 489
 if ($lastYouTubeActivity === false) {
490
-    $lastYouTubeActivityDateTime = new DateTime('2010-08-28');
490
+	$lastYouTubeActivityDateTime = new DateTime('2010-08-28');
491 491
 } else {
492
-    $lastYouTubeActivityDateTime = new DateTime($lastYouTubeActivity['updated_at']);
493
-    $lastYouTubeActivityDateTime->modify('-5 days');
492
+	$lastYouTubeActivityDateTime = new DateTime($lastYouTubeActivity['updated_at']);
493
+	$lastYouTubeActivityDateTime->modify('-5 days');
494 494
 }
495 495
 $newYouTubeActivity = $youTubeRepository->getYouTubesUpdatedSince($lastYouTubeActivityDateTime);
496 496
 foreach ($newYouTubeActivity as $youTube) {
497
-    $uniqueYouTubeCheck = $activityRepository->getActivityByTypeId('youtube', $youTube['id']);
498
-    if ($uniqueYouTubeCheck !== false) {
499
-        continue;
500
-    }
501
-
502
-    $youTubeData = json_decode($youTube['metadata'], true);
503
-
504
-    $message = sprintf(
505
-        'Favorited %s on YouTube.',
506
-        $youTubeData['snippet']['title']
507
-    );
508
-    $messageLong = sprintf(
509
-        "<iframe src=\"%s\" frameborder=\"0\" allowfullscreen></iframe>\n" .
510
-        "<p>Favorited <a href=\"%s\" target=\"_blank\" title=\"YouTube | %s\">%s</a> on YouTube.</p>",
511
-        "https://www.youtube.com/embed/{$youTubeData['contentDetails']['videoId']}",
512
-        "https://youtu.be/{$youTubeData['contentDetails']['videoId']}",
513
-        $youTubeData['snippet']['title'],
514
-        $youTubeData['snippet']['title']
515
-    );
516
-
517
-    $activityRepository->insertActivity(
518
-        $message,
519
-        $messageLong,
520
-        (new DateTime($youTube['datetime'])),
521
-        [],
522
-        'youtube',
523
-        $youTube['id']
524
-    );
497
+	$uniqueYouTubeCheck = $activityRepository->getActivityByTypeId('youtube', $youTube['id']);
498
+	if ($uniqueYouTubeCheck !== false) {
499
+		continue;
500
+	}
501
+
502
+	$youTubeData = json_decode($youTube['metadata'], true);
503
+
504
+	$message = sprintf(
505
+		'Favorited %s on YouTube.',
506
+		$youTubeData['snippet']['title']
507
+	);
508
+	$messageLong = sprintf(
509
+		"<iframe src=\"%s\" frameborder=\"0\" allowfullscreen></iframe>\n" .
510
+		"<p>Favorited <a href=\"%s\" target=\"_blank\" title=\"YouTube | %s\">%s</a> on YouTube.</p>",
511
+		"https://www.youtube.com/embed/{$youTubeData['contentDetails']['videoId']}",
512
+		"https://youtu.be/{$youTubeData['contentDetails']['videoId']}",
513
+		$youTubeData['snippet']['title'],
514
+		$youTubeData['snippet']['title']
515
+	);
516
+
517
+	$activityRepository->insertActivity(
518
+		$message,
519
+		$messageLong,
520
+		(new DateTime($youTube['datetime'])),
521
+		[],
522
+		'youtube',
523
+		$youTube['id']
524
+	);
525 525
 }
Please login to merge, or discard this patch.