@@ -5,13 +5,13 @@ discard block |
||
| 5 | 5 | ini_set('display_errors', 0); |
| 6 | 6 | |
| 7 | 7 | |
| 8 | -require_once __DIR__ . '/vendor/autoload.php'; |
|
| 8 | +require_once __DIR__.'/vendor/autoload.php'; |
|
| 9 | 9 | |
| 10 | 10 | $container = new Pimple\Container(); |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | // load the config for the application |
| 14 | -$config_path = __DIR__ . '/config.json'; |
|
| 14 | +$config_path = __DIR__.'/config.json'; |
|
| 15 | 15 | |
| 16 | 16 | $handle = @fopen($config_path, 'r'); |
| 17 | 17 | if ($handle === false) { |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | // timezones are fun |
| 31 | 31 | date_default_timezone_set('America/Phoenix'); // todo - belongs in configuration |
| 32 | -$container['default_timezone'] = function ($c) { |
|
| 32 | +$container['default_timezone'] = function($c) { |
|
| 33 | 33 | return new DateTimeZone('America/Phoenix'); |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | // configure the db connections holder |
| 38 | 38 | $db_connections = new Aura\Sql\ConnectionLocator(); |
| 39 | -$db_connections->setDefault(function () use ($config) { |
|
| 39 | +$db_connections->setDefault(function() use ($config) { |
|
| 40 | 40 | $connection = $config->database->slave; |
| 41 | 41 | return new Aura\Sql\ExtendedPdo( |
| 42 | 42 | "mysql:host={$connection->host}", |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $connection->password |
| 45 | 45 | ); |
| 46 | 46 | }); |
| 47 | -$db_connections->setWrite('master', function () use ($config) { |
|
| 47 | +$db_connections->setWrite('master', function() use ($config) { |
|
| 48 | 48 | $connection = $config->database->master; |
| 49 | 49 | return new Aura\Sql\ExtendedPdo( |
| 50 | 50 | "mysql:host={$connection->host}", |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $connection->password |
| 53 | 53 | ); |
| 54 | 54 | }); |
| 55 | -$db_connections->setRead('slave', function () use ($config) { |
|
| 55 | +$db_connections->setRead('slave', function() use ($config) { |
|
| 56 | 56 | $connection = $config->database->slave; |
| 57 | 57 | $pdo = new Aura\Sql\ExtendedPdo( |
| 58 | 58 | "mysql:host={$connection->host}", |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | // configure the comment service connection |
| 73 | -$container['comment_service_api'] = function () use ($config) { |
|
| 73 | +$container['comment_service_api'] = function() use ($config) { |
|
| 74 | 74 | $configuration = (new Jacobemerick\CommentService\Configuration()) |
| 75 | 75 | ->setUsername($config->comments->user) |
| 76 | 76 | ->setPassword($config->comments->password) |
@@ -84,16 +84,16 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | // setup mail handler |
| 87 | -$container['mail'] = $container->factory(function ($c) { |
|
| 87 | +$container['mail'] = $container->factory(function($c) { |
|
| 88 | 88 | return (new Jacobemerick\Archangel\Archangel())->setLogger($c['logger']); |
| 89 | 89 | }); |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | // setup the logger |
| 93 | -$container['setup_logger'] = $container->protect(function ($name) use ($container) { |
|
| 93 | +$container['setup_logger'] = $container->protect(function($name) use ($container) { |
|
| 94 | 94 | $logger = new Monolog\Logger($name); |
| 95 | 95 | |
| 96 | - $logPath = __DIR__ . "/logs/{$name}.log"; |
|
| 96 | + $logPath = __DIR__."/logs/{$name}.log"; |
|
| 97 | 97 | $streamHandler = new Monolog\Handler\StreamHandler($logPath, Monolog\Logger::INFO); |
| 98 | 98 | $streamHandler->setFormatter( |
| 99 | 99 | new Monolog\Formatter\LineFormatter("[%datetime%] %channel%.%level_name%: %message%\n") |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | // sets up shutdown function to display profiler |
| 124 | -register_shutdown_function(function () use ($container) { |
|
| 124 | +register_shutdown_function(function() use ($container) { |
|
| 125 | 125 | if ( |
| 126 | 126 | !isset($_COOKIE['debugger']) || |
| 127 | 127 | $_COOKIE['debugger'] != 'display' |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | ->getRead() |
| 134 | 134 | ->getProfiler() |
| 135 | 135 | ->getProfiles(); |
| 136 | - $dbProfiles = array_filter($dbProfiles, function ($profile) { |
|
| 136 | + $dbProfiles = array_filter($dbProfiles, function($profile) { |
|
| 137 | 137 | return $profile['function'] == 'perform'; |
| 138 | 138 | }); |
| 139 | - $dbProfiles = array_map(function ($profile) { |
|
| 139 | + $dbProfiles = array_map(function($profile) { |
|
| 140 | 140 | return [ |
| 141 | 141 | 'sql' => trim(preg_replace('/\s+/', ' ', $profile['statement'])), |
| 142 | 142 | 'parameters' => $profile['bind_values'], |
@@ -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 | { |