Completed
Push — master ( 2a5bde...88acae )
by Jacob
08:08
created
script/cron/generate-rss-feeds.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -21,14 +21,14 @@  discard block
 block discarded – undo
21 21
  * @return boolean
22 22
  */
23 23
 $buildFeed = function (Feed $feed, $folder, $name = 'rss') {
24
-    $tempFeed = __DIR__ . "/../../public/{$folder}/{$name}-new.xml";
25
-    $finalFeed = __DIR__ . "/../../public/{$folder}/{$name}.xml";
24
+	$tempFeed = __DIR__ . "/../../public/{$folder}/{$name}-new.xml";
25
+	$finalFeed = __DIR__ . "/../../public/{$folder}/{$name}.xml";
26 26
 
27
-    $feedHandle = fopen($tempFeed, 'w');
28
-    fwrite($feedHandle, $feed->render());
29
-    fclose($feedHandle);
27
+	$feedHandle = fopen($tempFeed, 'w');
28
+	fwrite($feedHandle, $feed->render());
29
+	fclose($feedHandle);
30 30
 
31
-    rename($tempFeed, $finalFeed);
31
+	rename($tempFeed, $finalFeed);
32 32
 };
33 33
 
34 34
 
@@ -47,56 +47,56 @@  discard block
 block discarded – undo
47 47
 $activeBlogPosts = $blogPostRepository->getActivePosts();
48 48
 
49 49
 foreach ($activeBlogPosts as $blogPost) {
50
-    $blogPostItem = new Item();
51
-
52
-    $blogPostItem->title($blogPost['title']);
53
-
54
-    $url = "https://blog.jacobemerick.com/{$blogPost['category']}/{$blogPost['path']}/";
55
-    $blogPostItem->url($url);
56
-    $blogPostItem->guid($url, true);
57
-
58
-    $description = $blogPost['body'];
59
-    $description = strip_tags($description);
60
-    $description = strtok($description, "\n");
61
-    if (strlen($description) > 250) {
62
-        $description = wordwrap($description, 250);
63
-        $description = strtok($description, "\n");
64
-        if (substr($description, -1) != '.') {
65
-            $description .= '…';
66
-        }
67
-    }
68
-    $description = html_entity_decode($description);
69
-    $blogPostItem->description($description);
70
-
71
-    $categoryUrl = "https://blog.jacobemerick.com/{$blogPost['category']}/";
72
-    $blogPostItem->category($blogPost['category'], $categoryUrl);
73
-
74
-    $pubDate = new DateTime($blogPost['date']);
75
-    $blogPostItem->pubDate($pubDate->getTimestamp());
76
-
77
-    $firstPhoto = Content::instance('FetchFirstPhoto', $blogPost['body'])->activate(true, 'large');
78
-    if (!empty($firstPhoto)) {
79
-        $firstPhotoPieces = sscanf($firstPhoto, '<img src="%s" height="%d" width="%d" alt="%s" />');
80
-        $firstPhotoPath = current($firstPhotoPieces);
81
-        $firstPhotoPath = trim($firstPhotoPath, '"');
82
-
83
-        $firstPhotoInternalPath = __DIR__ . '/../../public' . $firstPhotoPath;
84
-
85
-        $firstPhotoSize = filesize($firstPhotoInternalPath);
86
-
87
-        /**
88
-         * ugh, remote host does not have pecl fileinfo
89
-         *
90
-         * $fInfo = new finfo(FILEINFO_MIME_TYPE);
91
-         * $firstPhotoType = $fInfo->file($firstPhotoInternalPath);
92
-         * unset($fInfo);
93
-         **/
94
-        $firstPhotoType = 'image/jpeg';
95
-
96
-        $blogPostItem->enclosure("https://blog.jacobemerick.com{$firstPhotoPath}", $firstPhotoSize, $firstPhotoType);
97
-    }
98
-
99
-    $blogPostItem->appendTo($blogPostChannel);
50
+	$blogPostItem = new Item();
51
+
52
+	$blogPostItem->title($blogPost['title']);
53
+
54
+	$url = "https://blog.jacobemerick.com/{$blogPost['category']}/{$blogPost['path']}/";
55
+	$blogPostItem->url($url);
56
+	$blogPostItem->guid($url, true);
57
+
58
+	$description = $blogPost['body'];
59
+	$description = strip_tags($description);
60
+	$description = strtok($description, "\n");
61
+	if (strlen($description) > 250) {
62
+		$description = wordwrap($description, 250);
63
+		$description = strtok($description, "\n");
64
+		if (substr($description, -1) != '.') {
65
+			$description .= '&hellip;';
66
+		}
67
+	}
68
+	$description = html_entity_decode($description);
69
+	$blogPostItem->description($description);
70
+
71
+	$categoryUrl = "https://blog.jacobemerick.com/{$blogPost['category']}/";
72
+	$blogPostItem->category($blogPost['category'], $categoryUrl);
73
+
74
+	$pubDate = new DateTime($blogPost['date']);
75
+	$blogPostItem->pubDate($pubDate->getTimestamp());
76
+
77
+	$firstPhoto = Content::instance('FetchFirstPhoto', $blogPost['body'])->activate(true, 'large');
78
+	if (!empty($firstPhoto)) {
79
+		$firstPhotoPieces = sscanf($firstPhoto, '<img src="%s" height="%d" width="%d" alt="%s" />');
80
+		$firstPhotoPath = current($firstPhotoPieces);
81
+		$firstPhotoPath = trim($firstPhotoPath, '"');
82
+
83
+		$firstPhotoInternalPath = __DIR__ . '/../../public' . $firstPhotoPath;
84
+
85
+		$firstPhotoSize = filesize($firstPhotoInternalPath);
86
+
87
+		/**
88
+		 * ugh, remote host does not have pecl fileinfo
89
+		 *
90
+		 * $fInfo = new finfo(FILEINFO_MIME_TYPE);
91
+		 * $firstPhotoType = $fInfo->file($firstPhotoInternalPath);
92
+		 * unset($fInfo);
93
+		 **/
94
+		$firstPhotoType = 'image/jpeg';
95
+
96
+		$blogPostItem->enclosure("https://blog.jacobemerick.com{$firstPhotoPath}", $firstPhotoSize, $firstPhotoType);
97
+	}
98
+
99
+	$blogPostItem->appendTo($blogPostChannel);
100 100
 }
101 101
 
102 102
 $buildFeed($blogPostFeed, 'blog');
@@ -114,33 +114,33 @@  discard block
 block discarded – undo
114 114
 $activeBlogComments = $commentRepository->getActiveCommentsBySite('blog');
115 115
 
116 116
 foreach ($activeBlogComments as $blogComment) {
117
-    $blogCommentItem = new Item();
118
-
119
-    $blogCommentItem->title("Comment on '{$blogComment['title']}' from {$blogComment['name']}");
120
-
121
-    $url = "https://blog.jacobemerick.com/{$blogComment['category']}/{$blogComment['path']}/";
122
-    $url .= "#comment-{$blogComment['id']}";
123
-    $blogCommentItem->url($url);
124
-    $blogCommentItem->guid($url, true);
125
-
126
-    $description = $blogComment['body'];
127
-    $description = strip_tags($description);
128
-    $description = strtok($description, "\n");
129
-    if (strlen($description) > 250) {
130
-        $description = wordwrap($description, 250);
131
-        $description = strtok($description, "\n");
132
-        if (substr($description, -1) != '.') {
133
-            $description .= '&hellip;';
134
-        }
135
-    }
136
-    $description = html_entity_decode($description);
137
-    $description = trim($description);
138
-    $blogCommentItem->description($description);
139
-
140
-    $pubDate = new DateTime($blogComment['date']);
141
-    $blogCommentItem->pubDate($pubDate->getTimestamp());
142
-
143
-    $blogCommentItem->appendTo($blogCommentChannel);
117
+	$blogCommentItem = new Item();
118
+
119
+	$blogCommentItem->title("Comment on '{$blogComment['title']}' from {$blogComment['name']}");
120
+
121
+	$url = "https://blog.jacobemerick.com/{$blogComment['category']}/{$blogComment['path']}/";
122
+	$url .= "#comment-{$blogComment['id']}";
123
+	$blogCommentItem->url($url);
124
+	$blogCommentItem->guid($url, true);
125
+
126
+	$description = $blogComment['body'];
127
+	$description = strip_tags($description);
128
+	$description = strtok($description, "\n");
129
+	if (strlen($description) > 250) {
130
+		$description = wordwrap($description, 250);
131
+		$description = strtok($description, "\n");
132
+		if (substr($description, -1) != '.') {
133
+			$description .= '&hellip;';
134
+		}
135
+	}
136
+	$description = html_entity_decode($description);
137
+	$description = trim($description);
138
+	$blogCommentItem->description($description);
139
+
140
+	$pubDate = new DateTime($blogComment['date']);
141
+	$blogCommentItem->pubDate($pubDate->getTimestamp());
142
+
143
+	$blogCommentItem->appendTo($blogCommentChannel);
144 144
 }
145 145
 
146 146
 $buildFeed($blogCommentFeed, 'blog', 'rss-comments');
Please login to merge, or discard this patch.
utility/Loader.class.inc.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -173,17 +173,17 @@
 block discarded – undo
173 173
 		return self::instance()->is_live;
174 174
 	}
175 175
 
176
-    public static function getRootURL($site = '')
177
-    {
178
-        if (strlen($site) > 0) {
179
-            $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
180
-            if ($site == 'waterfalls' && self::instance()->is_live) {
181
-                return "{$protocol}://www.waterfallsofthekeweenaw.com/";
182
-            } else {
183
-                return $protocol . '://' . (self::instance()->is_live ? '' : 'dev.') . $site . '.jacobemerick.com/';
184
-            }
185
-        }
186
-        return '/';
187
-    }
176
+	public static function getRootURL($site = '')
177
+	{
178
+		if (strlen($site) > 0) {
179
+			$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
180
+			if ($site == 'waterfalls' && self::instance()->is_live) {
181
+				return "{$protocol}://www.waterfallsofthekeweenaw.com/";
182
+			} else {
183
+				return $protocol . '://' . (self::instance()->is_live ? '' : 'dev.') . $site . '.jacobemerick.com/';
184
+			}
185
+		}
186
+		return '/';
187
+	}
188 188
 
189 189
 }
Please login to merge, or discard this patch.
utility/URLDecode.class.inc.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,21 +24,21 @@
 block discarded – undo
24 24
 		
25 25
 		self::$array['host'] = $host;
26 26
 		
27
-    if (
28
-      $host == 'www.waterfallsofthekeweenaw.com' ||
29
-      $host == 'waterfallsofthekeweenaw.com'
30
-    ) {
27
+	if (
28
+	  $host == 'www.waterfallsofthekeweenaw.com' ||
29
+	  $host == 'waterfallsofthekeweenaw.com'
30
+	) {
31 31
 			self::$array['site'] = 'waterfalls';
32 32
 		} else {
33 33
 			self::$array['site'] = substr($host, 0, strpos($host, '.'));
34 34
 		}
35 35
 
36
-    $base = '';
37
-    $base .= (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
38
-    $base .= '://';
39
-    $base .= (!Loader::isLive()) ? 'dev' : '';
40
-    $base .= $host;
41
-    $base .= '/';
36
+	$base = '';
37
+	$base .= (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
38
+	$base .= '://';
39
+	$base .= (!Loader::isLive()) ? 'dev' : '';
40
+	$base .= $host;
41
+	$base .= '/';
42 42
 
43 43
 		self::$array['base'] = $base;
44 44
 		self::$array['uri'] = '/' . implode('/', $uri_array);
Please login to merge, or discard this patch.
router/Router.class.inc.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -75,19 +75,19 @@  discard block
 block discarded – undo
75 75
 		if($this->requires_trailing_slash() && substr($redirect_uri, -1) != '/')
76 76
 			$redirect_uri .= '/';
77 77
 		
78
-        if (URLDecode::getHost() == 'waterfalls.jacobemerick.com') {
79
-            $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
80
-            $redirect_uri = $protocol . '://' . (!Loader::isLive() ? 'dev' : 'www') . '.waterfallsofthekeweenaw.com' . $redirect_uri;
81
-        }
78
+		if (URLDecode::getHost() == 'waterfalls.jacobemerick.com') {
79
+			$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
80
+			$redirect_uri = $protocol . '://' . (!Loader::isLive() ? 'dev' : 'www') . '.waterfallsofthekeweenaw.com' . $redirect_uri;
81
+		}
82 82
         
83 83
 		if($redirect_uri == URLDecode::getURI())
84 84
 			return;
85 85
 		
86 86
 		$controller_check = $redirect_uri;
87 87
 		if(substr($redirect_uri, 0, 4) == 'http') {
88
-      $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
88
+	  $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
89 89
 			$controller_check = preg_replace('@^' . $protocol . '://([a-z\.]+)@', '', $redirect_uri);
90
-    }
90
+	}
91 91
 		
92 92
 		$controller = $this->get_controller($controller_check);
93 93
 		if($controller == '/Error404Controller')
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	{
139 139
 		return (
140 140
 			URLDecode::getExtension() != 'json' &&
141
-            strstr(URLDecode::getURI(), '#') === false);
141
+			strstr(URLDecode::getURI(), '#') === false);
142 142
 	}
143 143
 
144 144
 }
Please login to merge, or discard this patch.
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'], 1)
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'], 1)
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.
src/Domain/Stream/Goodread/MysqlGoodreadRepository.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -8,31 +8,31 @@
 block discarded – undo
8 8
 class MysqlGoodreadRepository implements GoodreadRepositoryInterface
9 9
 {
10 10
 
11
-    /** @var  ConnectionLocator */
12
-    protected $connections;
13
-
14
-    /**
15
-     * @param ConnectonLocator $connections
16
-     */
17
-    public function __construct(ConnectionLocator $connections)
18
-    {
19
-        $this->connections = $connections;
20
-    }
21
-
22
-    public function getGoodreadsUpdatedSince(DateTime $datetime)
23
-    {
24
-        $query = "
11
+	/** @var  ConnectionLocator */
12
+	protected $connections;
13
+
14
+	/**
15
+	 * @param ConnectonLocator $connections
16
+	 */
17
+	public function __construct(ConnectionLocator $connections)
18
+	{
19
+		$this->connections = $connections;
20
+	}
21
+
22
+	public function getGoodreadsUpdatedSince(DateTime $datetime)
23
+	{
24
+		$query = "
25 25
             SELECT *
26 26
             FROM `jpemeric_stream`.`goodread`
27 27
             WHERE `updated_at` >= :last_update";
28 28
 
29
-        $bindings = [
30
-            'last_update' => $datetime->format('Y-m-d H:i:s'),
31
-        ];
29
+		$bindings = [
30
+			'last_update' => $datetime->format('Y-m-d H:i:s'),
31
+		];
32 32
 
33
-        return $this
34
-            ->connections
35
-            ->getRead()
36
-            ->fetchAll($query, $bindings);
37
-    }
33
+		return $this
34
+			->connections
35
+			->getRead()
36
+			->fetchAll($query, $bindings);
37
+	}
38 38
 }
Please login to merge, or discard this patch.