protected function get_comments() { global $container; $repository = new Jacobemerick\Web\Domain\Comment\Comment\ServiceCommentRepository($container['comment_service_api']); $start = microtime(true); try { $comment_response = $repository->getComments( 'waterfallsofthekeweenaw.com', null, 1, 5, '-date' ); } catch (Exception $e) { $container['logger']->warning("CommentService | Sidebar | {$e->getMessage()}"); return; } $elapsed = microtime(true) - $start; global $container; $container['logger']->info("CommentService | Sidebar | {$elapsed}"); $array = array(); foreach($comment_response as $comment) { $body = Content::instance('CleanComment', $comment['body'])->activate(); $body = strip_tags($body); $comment_obj = new stdclass(); $comment_obj->description = Content::instance('SmartTrim', $body)->activate(50); $comment_obj->commenter = $comment['commenter']['name']; $comment_obj->link = $comment['url']; $array[] = $comment_obj; } return $array; }
protected function get_comment_array($site, $path) { global $container; $repository = new Jacobemerick\Web\Domain\Comment\Comment\ServiceCommentRepository($container['comment_service_api']); $start = microtime(true); try { $comment_response = $repository->getComments( $site, $path, 1, null, 'date' ); } catch (Exception $e) { $container['logger']->warning("CommentService | Path | {$e->getMessage()}"); return; } $elapsed = microtime(true) - $start; global $container; $container['logger']->info("CommentService | Path | {$elapsed}"); $array = array(); foreach((array) $comment_response as $comment) { $body = Content::instance('CleanComment', $comment['body'])->activate(); $body = strip_tags($body); $comment_obj = new stdclass(); $comment_obj->id = $comment['id']; $comment_obj->name = $comment['commenter']['name']; $comment_obj->url = $comment['commenter']['website']; $comment_obj->trusted = true; $comment_obj->date = $comment['date']->format('M j, \'y'); $comment_obj->body = $body; if ($comment['reply_to']) { $array[$comment['reply_to']]->replies[$comment['id']] = $comment_obj; continue; } $comment_obj->replies = []; $array[$comment['id']] = $comment_obj; } // todo figure out commenter obj // todo figure out how to handle errors or whatever // todo why is this even doing all this return [ 'comments' => $array, 'commenter' => [], 'errors' => [], 'comment_count' => count($comment_response), ]; }