@@ -8,81 +8,81 @@ discard block |
||
8 | 8 | abstract class DefaultPageController extends PageController |
9 | 9 | { |
10 | 10 | |
11 | - private static $RECENT_COMMENT_COUNT = 10; |
|
12 | - private static $MINIMUM_TAG_COUNT = 10; |
|
13 | - protected static $LENGTH_OF_TRIMMED_POST = 300; |
|
11 | + private static $RECENT_COMMENT_COUNT = 10; |
|
12 | + private static $MINIMUM_TAG_COUNT = 10; |
|
13 | + protected static $LENGTH_OF_TRIMMED_POST = 300; |
|
14 | 14 | |
15 | - protected static $BLOG_SITE_ID = 2; |
|
15 | + protected static $BLOG_SITE_ID = 2; |
|
16 | 16 | |
17 | - private static $INTRODUCTION_IMAGE_PATTERN = '<img src="/photo/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" />'; |
|
17 | + private static $INTRODUCTION_IMAGE_PATTERN = '<img src="/photo/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" />'; |
|
18 | 18 | |
19 | - protected function set_head_data() |
|
20 | - { |
|
19 | + protected function set_head_data() |
|
20 | + { |
|
21 | 21 | $this->set_head('rss_link', [ |
22 | - 'title' => 'Jacob Emerick Blog Feed', |
|
23 | - 'url' => '/rss.xml' |
|
22 | + 'title' => 'Jacob Emerick Blog Feed', |
|
23 | + 'url' => '/rss.xml' |
|
24 | 24 | ]); |
25 | 25 | $this->set_head('rss_comment_link', [ |
26 | - 'title' => 'Jacob Emerick Blog Comment Feed', |
|
27 | - 'url' => '/rss-comments.xml' |
|
26 | + 'title' => 'Jacob Emerick Blog Comment Feed', |
|
27 | + 'url' => '/rss-comments.xml' |
|
28 | 28 | ]); |
29 | 29 | |
30 | - $this->add_css('normalize'); |
|
31 | - $this->add_css('blog'); |
|
32 | - } |
|
30 | + $this->add_css('normalize'); |
|
31 | + $this->add_css('blog'); |
|
32 | + } |
|
33 | 33 | |
34 | - protected function get_introduction() |
|
35 | - { |
|
36 | - return; |
|
37 | - } |
|
34 | + protected function get_introduction() |
|
35 | + { |
|
36 | + return; |
|
37 | + } |
|
38 | 38 | |
39 | - protected function get_introduction_image($id) |
|
40 | - { |
|
41 | - Loader::load('collector', 'image/PhotoCollector'); |
|
42 | - $photo_result = PhotoCollector::getRow($id); |
|
39 | + protected function get_introduction_image($id) |
|
40 | + { |
|
41 | + Loader::load('collector', 'image/PhotoCollector'); |
|
42 | + $photo_result = PhotoCollector::getRow($id); |
|
43 | 43 | |
44 | - if($photo_result == null) |
|
45 | - return; |
|
44 | + if($photo_result == null) |
|
45 | + return; |
|
46 | 46 | |
47 | - $name = $photo_result->name; |
|
48 | - $category = $photo_result->category; |
|
49 | - $size = 'medium'; |
|
50 | - $height = 375; |
|
51 | - $width = 500; |
|
52 | - $description = $photo_result->description; |
|
47 | + $name = $photo_result->name; |
|
48 | + $category = $photo_result->category; |
|
49 | + $size = 'medium'; |
|
50 | + $height = 375; |
|
51 | + $width = 500; |
|
52 | + $description = $photo_result->description; |
|
53 | 53 | |
54 | - return sprintf(self::$INTRODUCTION_IMAGE_PATTERN, $category, $name, $size, $height, $width, $description); |
|
55 | - } |
|
54 | + return sprintf(self::$INTRODUCTION_IMAGE_PATTERN, $category, $name, $size, $height, $width, $description); |
|
55 | + } |
|
56 | 56 | |
57 | - protected function set_body_data() |
|
58 | - { |
|
59 | - $this->set_body('introduction', $this->get_introduction()); |
|
60 | - $this->set_body('right_side', $this->get_right_side()); |
|
61 | - $this->set_body('activity_array', $this->get_recent_activity()); |
|
57 | + protected function set_body_data() |
|
58 | + { |
|
59 | + $this->set_body('introduction', $this->get_introduction()); |
|
60 | + $this->set_body('right_side', $this->get_right_side()); |
|
61 | + $this->set_body('activity_array', $this->get_recent_activity()); |
|
62 | 62 | |
63 | - $this->set_body_view('Page'); |
|
64 | - } |
|
63 | + $this->set_body_view('Page'); |
|
64 | + } |
|
65 | 65 | |
66 | - final protected function format_post($post, $trim = false) |
|
67 | - { |
|
68 | - $post_object = new stdclass(); |
|
66 | + final protected function format_post($post, $trim = false) |
|
67 | + { |
|
68 | + $post_object = new stdclass(); |
|
69 | 69 | |
70 | - $post_object->title = $post['title']; |
|
71 | - $post_object->path = "/{$post['category']}/{$post['path']}/"; |
|
72 | - $post_object->category = ucwords(str_replace('-', ' ', $post['category'])); |
|
73 | - $post_object->category_link = "/{$post['category']}/"; |
|
74 | - // $post_object->comment_count = $this->get_comments_for_post($post); |
|
75 | - $post_object->tags = $this->get_tags_for_post($post); |
|
76 | - $post_object->image = Content::instance('FetchFirstPhoto', $post['body'])->activate(false, 'small'); |
|
77 | - $post_object->body = $this->get_body_for_post($post, $trim); |
|
78 | - $post_object->date = $this->get_parsed_date($post['date']); |
|
70 | + $post_object->title = $post['title']; |
|
71 | + $post_object->path = "/{$post['category']}/{$post['path']}/"; |
|
72 | + $post_object->category = ucwords(str_replace('-', ' ', $post['category'])); |
|
73 | + $post_object->category_link = "/{$post['category']}/"; |
|
74 | + // $post_object->comment_count = $this->get_comments_for_post($post); |
|
75 | + $post_object->tags = $this->get_tags_for_post($post); |
|
76 | + $post_object->image = Content::instance('FetchFirstPhoto', $post['body'])->activate(false, 'small'); |
|
77 | + $post_object->body = $this->get_body_for_post($post, $trim); |
|
78 | + $post_object->date = $this->get_parsed_date($post['date']); |
|
79 | 79 | |
80 | - return $post_object; |
|
81 | - } |
|
80 | + return $post_object; |
|
81 | + } |
|
82 | 82 | |
83 | - final private function get_comments_for_post($post) |
|
84 | - { |
|
85 | - $count = CommentCollector::getCommentCountForURL(self::$BLOG_SITE_ID, $post['path']); |
|
83 | + final private function get_comments_for_post($post) |
|
84 | + { |
|
85 | + $count = CommentCollector::getCommentCountForURL(self::$BLOG_SITE_ID, $post['path']); |
|
86 | 86 | $count_from_service = $this->get_comments_for_post_from_service($post); |
87 | 87 | |
88 | 88 | if ($count_from_service !== null && $count_from_service != $count) { |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $container['console']->log("{$count}, {$count_from_service} in service"); |
92 | 92 | } |
93 | 93 | return $count; |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | 96 | final private function get_comments_for_post_from_service($post) |
97 | 97 | { |
@@ -127,106 +127,106 @@ discard block |
||
127 | 127 | return count($comment_response); |
128 | 128 | } |
129 | 129 | |
130 | - final private function get_tags_for_post($post) |
|
131 | - { |
|
130 | + final private function get_tags_for_post($post) |
|
131 | + { |
|
132 | 132 | global $container; |
133 | 133 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
134 | 134 | $tag_result = $repository->getTagsForPost($post['id']); |
135 | 135 | |
136 | 136 | $tag_array = array(); |
137 | - foreach($tag_result as $tag) |
|
138 | - { |
|
139 | - $tag_object = new stdclass(); |
|
140 | - $tag_object->name = $tag['tag']; |
|
141 | - $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
142 | - $tag_array[] = $tag_object; |
|
143 | - } |
|
144 | - return $tag_array; |
|
145 | - } |
|
137 | + foreach($tag_result as $tag) |
|
138 | + { |
|
139 | + $tag_object = new stdclass(); |
|
140 | + $tag_object->name = $tag['tag']; |
|
141 | + $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
142 | + $tag_array[] = $tag_object; |
|
143 | + } |
|
144 | + return $tag_array; |
|
145 | + } |
|
146 | 146 | |
147 | - final private function get_body_for_post($post, $trim) |
|
148 | - { |
|
149 | - $body = $post['body']; |
|
147 | + final private function get_body_for_post($post, $trim) |
|
148 | + { |
|
149 | + $body = $post['body']; |
|
150 | 150 | |
151 | - if($trim) |
|
152 | - $body = Content::instance('SmartTrim', $body)->activate(self::$LENGTH_OF_TRIMMED_POST); |
|
151 | + if($trim) |
|
152 | + $body = Content::instance('SmartTrim', $body)->activate(self::$LENGTH_OF_TRIMMED_POST); |
|
153 | 153 | |
154 | - $body = Content::instance('FixPhoto', $body)->activate(false, 'standard'); |
|
155 | - $body = Content::instance('MarkupCode', $body)->activate(); |
|
154 | + $body = Content::instance('FixPhoto', $body)->activate(false, 'standard'); |
|
155 | + $body = Content::instance('MarkupCode', $body)->activate(); |
|
156 | 156 | |
157 | - return $body; |
|
158 | - } |
|
157 | + return $body; |
|
158 | + } |
|
159 | 159 | |
160 | - final protected function get_right_side() |
|
161 | - { |
|
162 | - $side_array = array(); |
|
163 | - $side_array['tags'] = $this->get_tag_cloud(); |
|
164 | - $side_array['comments'] = $this->get_comments(); |
|
165 | - return $side_array; |
|
166 | - } |
|
160 | + final protected function get_right_side() |
|
161 | + { |
|
162 | + $side_array = array(); |
|
163 | + $side_array['tags'] = $this->get_tag_cloud(); |
|
164 | + $side_array['comments'] = $this->get_comments(); |
|
165 | + return $side_array; |
|
166 | + } |
|
167 | 167 | |
168 | - final private function get_tag_cloud() |
|
169 | - { |
|
168 | + final private function get_tag_cloud() |
|
169 | + { |
|
170 | 170 | global $container; |
171 | 171 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
172 | 172 | $tag_result = $repository->getTagCloud(); |
173 | 173 | |
174 | - $maximum_tag_count = $this->get_maximum_tag_count($tag_result); |
|
174 | + $maximum_tag_count = $this->get_maximum_tag_count($tag_result); |
|
175 | 175 | |
176 | - $cloud_array = array(); |
|
177 | - foreach($tag_result as $tag) |
|
178 | - { |
|
179 | - if($tag['count'] < self::$MINIMUM_TAG_COUNT) |
|
180 | - continue; |
|
176 | + $cloud_array = array(); |
|
177 | + foreach($tag_result as $tag) |
|
178 | + { |
|
179 | + if($tag['count'] < self::$MINIMUM_TAG_COUNT) |
|
180 | + continue; |
|
181 | 181 | |
182 | - $tag_object = new stdclass(); |
|
183 | - $tag_object->name = $tag['tag']; |
|
184 | - $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
185 | - $tag_object->scalar = floor(($tag['count'] - 1) * (9 / ($maximum_tag_count - self::$MINIMUM_TAG_COUNT))); |
|
186 | - $cloud_array[] = $tag_object; |
|
187 | - } |
|
182 | + $tag_object = new stdclass(); |
|
183 | + $tag_object->name = $tag['tag']; |
|
184 | + $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
185 | + $tag_object->scalar = floor(($tag['count'] - 1) * (9 / ($maximum_tag_count - self::$MINIMUM_TAG_COUNT))); |
|
186 | + $cloud_array[] = $tag_object; |
|
187 | + } |
|
188 | 188 | |
189 | - return $cloud_array; |
|
190 | - } |
|
189 | + return $cloud_array; |
|
190 | + } |
|
191 | 191 | |
192 | - final private function get_maximum_tag_count($tag_result) |
|
193 | - { |
|
194 | - $maximum = 1; |
|
192 | + final private function get_maximum_tag_count($tag_result) |
|
193 | + { |
|
194 | + $maximum = 1; |
|
195 | 195 | |
196 | - foreach($tag_result as $tag) |
|
197 | - { |
|
198 | - if($tag['count'] > $maximum) |
|
199 | - $maximum = $tag['count']; |
|
200 | - } |
|
201 | - return $maximum; |
|
202 | - } |
|
196 | + foreach($tag_result as $tag) |
|
197 | + { |
|
198 | + if($tag['count'] > $maximum) |
|
199 | + $maximum = $tag['count']; |
|
200 | + } |
|
201 | + return $maximum; |
|
202 | + } |
|
203 | 203 | |
204 | - final private function get_comments() |
|
205 | - { |
|
206 | - $comment_array = CommentCollector::getRecentBlogComments(self::$RECENT_COMMENT_COUNT); |
|
204 | + final private function get_comments() |
|
205 | + { |
|
206 | + $comment_array = CommentCollector::getRecentBlogComments(self::$RECENT_COMMENT_COUNT); |
|
207 | 207 | |
208 | - $array = array(); |
|
209 | - foreach($comment_array as $comment) |
|
210 | - { |
|
211 | - $body = $comment->body; |
|
212 | - $body = strip_tags($body); |
|
208 | + $array = array(); |
|
209 | + foreach($comment_array as $comment) |
|
210 | + { |
|
211 | + $body = $comment->body; |
|
212 | + $body = strip_tags($body); |
|
213 | 213 | |
214 | - $comment_obj = new stdclass(); |
|
215 | - $comment_obj->description = Content::instance('SmartTrim', $body)->activate(30); |
|
216 | - $comment_obj->commenter = $comment->name; |
|
217 | - $comment_obj->link = Loader::getRootURL() . "{$comment->category}/{$comment->path}/#comment-{$comment->id}"; |
|
218 | - $array[] = $comment_obj; |
|
219 | - } |
|
214 | + $comment_obj = new stdclass(); |
|
215 | + $comment_obj->description = Content::instance('SmartTrim', $body)->activate(30); |
|
216 | + $comment_obj->commenter = $comment->name; |
|
217 | + $comment_obj->link = Loader::getRootURL() . "{$comment->category}/{$comment->path}/#comment-{$comment->id}"; |
|
218 | + $array[] = $comment_obj; |
|
219 | + } |
|
220 | 220 | |
221 | 221 | $comment_service_array = $this->get_comments_from_service(); |
222 | 222 | if ($comment_service_array !== null && $comment_service_array !== $array) { |
223 | - global $container; |
|
224 | - $container['console']->log('Mismatch between comment service and legacy db'); |
|
225 | - $container['console']->log($comment_service_array[0]); |
|
226 | - $container['console']->log($array[0]); |
|
223 | + global $container; |
|
224 | + $container['console']->log('Mismatch between comment service and legacy db'); |
|
225 | + $container['console']->log($comment_service_array[0]); |
|
226 | + $container['console']->log($array[0]); |
|
227 | + } |
|
228 | + return $array; |
|
227 | 229 | } |
228 | - return $array; |
|
229 | - } |
|
230 | 230 | |
231 | 231 | final private function get_comments_from_service() |
232 | 232 | { |