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