@@ -4,7 +4,7 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface CommentRepositoryInterface |
| 6 | 6 | { |
| 7 | - public function createComment(array $comment); |
|
| 8 | - public function getComment($commentId); |
|
| 9 | - public function getComments($domain = null, $path = null, $page = null, $perPage = null, $order = null); |
|
| 7 | + public function createComment(array $comment); |
|
| 8 | + public function getComment($commentId); |
|
| 9 | + public function getComments($domain = null, $path = null, $page = null, $perPage = null, $order = null); |
|
| 10 | 10 | } |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface CommenterRepositoryInterface |
| 6 | 6 | { |
| 7 | - public function createCommenter(array $commenter); |
|
| 8 | - public function getCommenter($commenterId); |
|
| 9 | - public function getCommenters($page = null, $perPage = null); |
|
| 7 | + public function createCommenter(array $commenter); |
|
| 8 | + public function getCommenter($commenterId); |
|
| 9 | + public function getCommenters($page = null, $perPage = null); |
|
| 10 | 10 | } |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | parent::__construct(); |
| 25 | 25 | |
| 26 | - global $container; |
|
| 27 | - $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
| 28 | - $this->post = $repository->findPostByPath(URLDecode::getPiece(2)); |
|
| 26 | + global $container; |
|
| 27 | + $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
| 28 | + $this->post = $repository->findPostByPath(URLDecode::getPiece(2)); |
|
| 29 | 29 | |
| 30 | 30 | if($this->post == null) |
| 31 | 31 | $this->eject(); |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | Loader::getRootUrl('blog') . $this->post['category'] . '/' . $this->post['path'] . '/', |
| 37 | 37 | $this->post['title']); |
| 38 | 38 | |
| 39 | - global $container; |
|
| 40 | - $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
| 41 | - $this->tags = $repository->getTagsForPost($this->post['id']); |
|
| 39 | + global $container; |
|
| 40 | + $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
| 41 | + $this->tags = $repository->getTagsForPost($this->post['id']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | protected function set_head_data() |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | $this->set_keywords($this->get_post_keywords()); |
| 51 | 51 | $this->set_author(self::$AUTHOR); |
| 52 | 52 | |
| 53 | - $photo = Content::instance('FetchFirstPhoto', $this->post['body'])->activate(true); |
|
| 54 | - $photo = preg_match('/^<img src="([a-z-:\.\/]+)" [^>]+>$/', $photo, $matches); |
|
| 55 | - $this->set_head('thumbnail', $matches[1]); |
|
| 53 | + $photo = Content::instance('FetchFirstPhoto', $this->post['body'])->activate(true); |
|
| 54 | + $photo = preg_match('/^<img src="([a-z-:\.\/]+)" [^>]+>$/', $photo, $matches); |
|
| 55 | + $this->set_head('thumbnail', $matches[1]); |
|
| 56 | 56 | |
| 57 | 57 | if (array_key_exists($this->post['id'], self::$DEPRECATED_BLOGS)) { |
| 58 | 58 | $log_id = self::$DEPRECATED_BLOGS[$this->post['id']]; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | 'author' => self::$AUTHOR, |
| 80 | 80 | 'author_url' => self::$AUTHOR_URL, |
| 81 | 81 | 'comment_array' => $this->get_comment_array("{$this->post['category']}/{$this->post['path']}"), |
| 82 | - )); |
|
| 82 | + )); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | protected function get_post_description() |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | $post = new stdclass(); |
| 129 | 129 | |
| 130 | - if ( |
|
| 131 | - strpos($post_row['title'], 'Rainy Supe Loop') === 0 || |
|
| 132 | - strpos($post_row['title'], 'Malapais Loop') === 0 || |
|
| 133 | - strpos($post_row['title'], 'Mazatzal Peak Loop') === 0 || |
|
| 134 | - strpos($post_row['title'], 'Dripping Springs Loop') === 0 |
|
| 135 | - ) { |
|
| 136 | - $title = $post_row['title']; |
|
| 137 | - $title = explode(':', $title); |
|
| 138 | - $title = array_pop($title); |
|
| 139 | - $title = trim($title); |
|
| 140 | - $post->title = $title; |
|
| 141 | - } else if (strpos($post_row['title'], 'Isle Royale') === 0) { |
|
| 130 | + if ( |
|
| 131 | + strpos($post_row['title'], 'Rainy Supe Loop') === 0 || |
|
| 132 | + strpos($post_row['title'], 'Malapais Loop') === 0 || |
|
| 133 | + strpos($post_row['title'], 'Mazatzal Peak Loop') === 0 || |
|
| 134 | + strpos($post_row['title'], 'Dripping Springs Loop') === 0 |
|
| 135 | + ) { |
|
| 136 | + $title = $post_row['title']; |
|
| 137 | + $title = explode(':', $title); |
|
| 138 | + $title = array_pop($title); |
|
| 139 | + $title = trim($title); |
|
| 140 | + $post->title = $title; |
|
| 141 | + } else if (strpos($post_row['title'], 'Isle Royale') === 0) { |
|
| 142 | 142 | $title = $post_row['title']; |
| 143 | 143 | $title = explode(',', $title); |
| 144 | 144 | $title = array_pop($title); |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | private $series_posts; |
| 170 | 170 | private function fetch_series_posts() |
| 171 | 171 | { |
| 172 | - if(!isset($this->series_posts)) { |
|
| 173 | - global $container; |
|
| 174 | - $repository = new Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository($container['db_connection_locator']); |
|
| 175 | - $this->series_posts = $repository->getSeriesForPost($this->post['id']); |
|
| 176 | - } |
|
| 177 | - return $this->series_posts; |
|
| 172 | + if(!isset($this->series_posts)) { |
|
| 173 | + global $container; |
|
| 174 | + $repository = new Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository($container['db_connection_locator']); |
|
| 175 | + $this->series_posts = $repository->getSeriesForPost($this->post['id']); |
|
| 176 | + } |
|
| 177 | + return $this->series_posts; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | private function get_related_posts() |
@@ -192,11 +192,11 @@ discard block |
||
| 192 | 192 | $exclude_post_array[] = $series_post['post']; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - global $container; |
|
| 196 | - $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
| 197 | - $post_result = $repository->getActivePostsByRelatedTags($this->post['id']); |
|
| 195 | + global $container; |
|
| 196 | + $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
| 197 | + $post_result = $repository->getActivePostsByRelatedTags($this->post['id']); |
|
| 198 | 198 | |
| 199 | - $post_array = array(); |
|
| 199 | + $post_array = array(); |
|
| 200 | 200 | |
| 201 | 201 | foreach($post_result as $post_row) |
| 202 | 202 | { |
@@ -213,69 +213,69 @@ discard block |
||
| 213 | 213 | return $post_array; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - protected function get_comment_array($path) |
|
| 217 | - { |
|
| 218 | - global $config; |
|
| 219 | - $configuration = new Jacobemerick\CommentService\Configuration(); |
|
| 220 | - $configuration->setUsername($config->comments->user); |
|
| 221 | - $configuration->setPassword($config->comments->password); |
|
| 222 | - $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
| 223 | - $configuration->setHost($config->comments->host); |
|
| 224 | - $configuration->setCurlTimeout($config->comments->timeout); |
|
| 216 | + protected function get_comment_array($path) |
|
| 217 | + { |
|
| 218 | + global $config; |
|
| 219 | + $configuration = new Jacobemerick\CommentService\Configuration(); |
|
| 220 | + $configuration->setUsername($config->comments->user); |
|
| 221 | + $configuration->setPassword($config->comments->password); |
|
| 222 | + $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
| 223 | + $configuration->setHost($config->comments->host); |
|
| 224 | + $configuration->setCurlTimeout($config->comments->timeout); |
|
| 225 | 225 | |
| 226 | - $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
| 227 | - $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
| 226 | + $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
| 227 | + $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
| 228 | 228 | |
| 229 | - $start = microtime(true); |
|
| 230 | - try { |
|
| 231 | - $comment_response = $api->getComments( |
|
| 232 | - 1, |
|
| 233 | - null, |
|
| 234 | - 'date', |
|
| 235 | - 'blog.jacobemerick.com', |
|
| 236 | - $path |
|
| 237 | - ); |
|
| 238 | - } catch (Exception $e) { |
|
| 239 | - global $container; |
|
| 240 | - $container['logger']->warning("CommentService | Path | {$e->getMessage()}"); |
|
| 241 | - return; |
|
| 242 | - } |
|
| 229 | + $start = microtime(true); |
|
| 230 | + try { |
|
| 231 | + $comment_response = $api->getComments( |
|
| 232 | + 1, |
|
| 233 | + null, |
|
| 234 | + 'date', |
|
| 235 | + 'blog.jacobemerick.com', |
|
| 236 | + $path |
|
| 237 | + ); |
|
| 238 | + } catch (Exception $e) { |
|
| 239 | + global $container; |
|
| 240 | + $container['logger']->warning("CommentService | Path | {$e->getMessage()}"); |
|
| 241 | + return; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - $elapsed = microtime(true) - $start; |
|
| 245 | - global $container; |
|
| 246 | - $container['logger']->info("CommentService | Path | {$elapsed}"); |
|
| 244 | + $elapsed = microtime(true) - $start; |
|
| 245 | + global $container; |
|
| 246 | + $container['logger']->info("CommentService | Path | {$elapsed}"); |
|
| 247 | 247 | |
| 248 | - $array = array(); |
|
| 249 | - foreach((array) $comment_response as $comment) |
|
| 250 | - { |
|
| 251 | - $body = $comment->getBody(); |
|
| 252 | - $body = Content::instance('CleanComment', $body)->activate(); |
|
| 253 | - $body = strip_tags($body); |
|
| 248 | + $array = array(); |
|
| 249 | + foreach((array) $comment_response as $comment) |
|
| 250 | + { |
|
| 251 | + $body = $comment->getBody(); |
|
| 252 | + $body = Content::instance('CleanComment', $body)->activate(); |
|
| 253 | + $body = strip_tags($body); |
|
| 254 | 254 | |
| 255 | - $comment_obj = new stdclass(); |
|
| 256 | - $comment_obj->id = $comment->getId(); |
|
| 257 | - $comment_obj->name = $comment->getCommenter()->getName(); |
|
| 258 | - $comment_obj->url = $comment->getCommenter()->getWebsite(); |
|
| 259 | - $comment_obj->trusted = true; |
|
| 260 | - $comment_obj->date = $comment->getDate()->format('M j, \'y'); |
|
| 261 | - $comment_obj->body = $body; |
|
| 255 | + $comment_obj = new stdclass(); |
|
| 256 | + $comment_obj->id = $comment->getId(); |
|
| 257 | + $comment_obj->name = $comment->getCommenter()->getName(); |
|
| 258 | + $comment_obj->url = $comment->getCommenter()->getWebsite(); |
|
| 259 | + $comment_obj->trusted = true; |
|
| 260 | + $comment_obj->date = $comment->getDate()->format('M j, \'y'); |
|
| 261 | + $comment_obj->body = $body; |
|
| 262 | 262 | |
| 263 | - if ($comment->getReplyTo()) { |
|
| 264 | - $array[$comment->getReplyTo()]->replies[$comment->getId()] = $comment_obj; |
|
| 265 | - continue; |
|
| 266 | - } |
|
| 263 | + if ($comment->getReplyTo()) { |
|
| 264 | + $array[$comment->getReplyTo()]->replies[$comment->getId()] = $comment_obj; |
|
| 265 | + continue; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - $comment_obj->replies = []; |
|
| 269 | - $array[$comment->getId()] = $comment_obj; |
|
| 270 | - } |
|
| 268 | + $comment_obj->replies = []; |
|
| 269 | + $array[$comment->getId()] = $comment_obj; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - // todo figure out commenter obj |
|
| 273 | - // todo figure out how to handle errors or whatever |
|
| 274 | - return [ |
|
| 275 | - 'comments' => $array, |
|
| 276 | - 'commenter' => [], |
|
| 277 | - 'errors' => [], |
|
| 278 | - 'comment_count' => count($comment_response), |
|
| 279 | - ]; |
|
| 280 | - } |
|
| 272 | + // todo figure out commenter obj |
|
| 273 | + // todo figure out how to handle errors or whatever |
|
| 274 | + return [ |
|
| 275 | + 'comments' => $array, |
|
| 276 | + 'commenter' => [], |
|
| 277 | + 'errors' => [], |
|
| 278 | + 'comment_count' => count($comment_response), |
|
| 279 | + ]; |
|
| 280 | + } |
|
| 281 | 281 | } |