@@ -5,13 +5,13 @@ discard block |
||
| 5 | 5 | final class CommentCollector extends Collector |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - public static function getCommenterByFields($name, $email, $website) |
|
| 9 | - { |
|
| 10 | - $name = self::escape($name); |
|
| 11 | - $email = self::escape($email); |
|
| 12 | - $website = self::escape($website); |
|
| 8 | + public static function getCommenterByFields($name, $email, $website) |
|
| 9 | + { |
|
| 10 | + $name = self::escape($name); |
|
| 11 | + $email = self::escape($email); |
|
| 12 | + $website = self::escape($website); |
|
| 13 | 13 | |
| 14 | - $query = " |
|
| 14 | + $query = " |
|
| 15 | 15 | SELECT |
| 16 | 16 | * |
| 17 | 17 | FROM |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | `url` = '{$website}' |
| 23 | 23 | LIMIT 1"; |
| 24 | 24 | |
| 25 | - return self::run_row_query($query); |
|
| 26 | - } |
|
| 25 | + return self::run_row_query($query); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public static function getCommentByBody($body) |
|
| 29 | - { |
|
| 30 | - $body = self::escape($body); |
|
| 28 | + public static function getCommentByBody($body) |
|
| 29 | + { |
|
| 30 | + $body = self::escape($body); |
|
| 31 | 31 | |
| 32 | - $query = " |
|
| 32 | + $query = " |
|
| 33 | 33 | SELECT |
| 34 | 34 | * |
| 35 | 35 | FROM |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | `body` = '{$body}' |
| 39 | 39 | LIMIT 1"; |
| 40 | 40 | |
| 41 | - return self::run_row_query($query); |
|
| 42 | - } |
|
| 41 | + return self::run_row_query($query); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public static function getCommentPageByURL($path, $site) |
|
| 45 | - { |
|
| 46 | - $path = self::escape($path); |
|
| 44 | + public static function getCommentPageByURL($path, $site) |
|
| 45 | + { |
|
| 46 | + $path = self::escape($path); |
|
| 47 | 47 | |
| 48 | - $query = " |
|
| 48 | + $query = " |
|
| 49 | 49 | SELECT |
| 50 | 50 | * |
| 51 | 51 | FROM |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | LIMIT |
| 57 | 57 | 1"; |
| 58 | 58 | |
| 59 | - return self::run_row_query($query); |
|
| 60 | - } |
|
| 59 | + return self::run_row_query($query); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public static function getNotificationForPage($comment_page) |
|
| 63 | - { |
|
| 64 | - $query = " |
|
| 62 | + public static function getNotificationForPage($comment_page) |
|
| 63 | + { |
|
| 64 | + $query = " |
|
| 65 | 65 | SELECT |
| 66 | 66 | `name`, |
| 67 | 67 | `email` |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | ORDER BY |
| 81 | 81 | `date` DESC"; |
| 82 | 82 | |
| 83 | - return self::run_query($query); |
|
| 84 | - } |
|
| 83 | + return self::run_query($query); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public static function getRecentBlogComments($count) |
|
| 87 | - { |
|
| 88 | - $query = " |
|
| 86 | + public static function getRecentBlogComments($count) |
|
| 87 | + { |
|
| 88 | + $query = " |
|
| 89 | 89 | SELECT |
| 90 | 90 | `comment_meta`.`id`, |
| 91 | 91 | `post`.`category`, |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | `comment_meta`.`date` DESC |
| 112 | 112 | LIMIT {$count}"; |
| 113 | 113 | |
| 114 | - return self::run_query($query); |
|
| 115 | - } |
|
| 114 | + return self::run_query($query); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | public static function getRecentWaterfallComments($count = 5) |
| 118 | 118 | { |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | return self::run_query($query); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public static function getCommentsForURL($site, $path, $commenter = 0) |
|
| 163 | - { |
|
| 164 | - $path = self::escape($path); |
|
| 162 | + public static function getCommentsForURL($site, $path, $commenter = 0) |
|
| 163 | + { |
|
| 164 | + $path = self::escape($path); |
|
| 165 | 165 | |
| 166 | - if($commenter != 0) |
|
| 167 | - $trusted_commenter_clause = "(`commenter`.`trusted` = '1' || `commenter`.`id` = '{$commenter}')"; |
|
| 168 | - else |
|
| 169 | - $trusted_commenter_clause = "`commenter`.`trusted` = '1'"; |
|
| 166 | + if($commenter != 0) |
|
| 167 | + $trusted_commenter_clause = "(`commenter`.`trusted` = '1' || `commenter`.`id` = '{$commenter}')"; |
|
| 168 | + else |
|
| 169 | + $trusted_commenter_clause = "`commenter`.`trusted` = '1'"; |
|
| 170 | 170 | |
| 171 | - $query = " |
|
| 171 | + $query = " |
|
| 172 | 172 | SELECT |
| 173 | 173 | `comment_meta`.`id`, |
| 174 | 174 | `comment_meta`.`reply`, |
@@ -194,14 +194,14 @@ discard block |
||
| 194 | 194 | ORDER BY |
| 195 | 195 | `comment_meta`.`date`"; |
| 196 | 196 | |
| 197 | - return self::run_query($query); |
|
| 198 | - } |
|
| 197 | + return self::run_query($query); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - public static function getCommentCountForURL($site, $path) |
|
| 201 | - { |
|
| 202 | - $path = self::escape($path); |
|
| 200 | + public static function getCommentCountForURL($site, $path) |
|
| 201 | + { |
|
| 202 | + $path = self::escape($path); |
|
| 203 | 203 | |
| 204 | - $query = " |
|
| 204 | + $query = " |
|
| 205 | 205 | SELECT |
| 206 | 206 | COUNT(1) AS `count` |
| 207 | 207 | FROM |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | ORDER BY |
| 219 | 219 | `comment_meta`.`date`"; |
| 220 | 220 | |
| 221 | - return self::get_count($query); |
|
| 222 | - } |
|
| 221 | + return self::get_count($query); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | } |
| 225 | 225 | \ No newline at end of file |
@@ -5,29 +5,29 @@ |
||
| 5 | 5 | abstract class Collector |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - protected static function run_query($query) |
|
| 9 | - { |
|
| 10 | - return Database::select($query); |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - protected static function run_row_query($query) |
|
| 14 | - { |
|
| 15 | - return Database::selectRow($query); |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - protected static function get_count($query) |
|
| 19 | - { |
|
| 20 | - return Database::selectRow($query)->count; |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - protected static function check_exists($query) |
|
| 24 | - { |
|
| 25 | - return Database::selectRow($query) !== null; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - protected static function escape($string) |
|
| 29 | - { |
|
| 30 | - return Database::escape($string); |
|
| 31 | - } |
|
| 8 | + protected static function run_query($query) |
|
| 9 | + { |
|
| 10 | + return Database::select($query); |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + protected static function run_row_query($query) |
|
| 14 | + { |
|
| 15 | + return Database::selectRow($query); |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + protected static function get_count($query) |
|
| 19 | + { |
|
| 20 | + return Database::selectRow($query)->count; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + protected static function check_exists($query) |
|
| 24 | + { |
|
| 25 | + return Database::selectRow($query) !== null; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + protected static function escape($string) |
|
| 29 | + { |
|
| 30 | + return Database::escape($string); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | } |
@@ -5,136 +5,136 @@ |
||
| 5 | 5 | final class TagController extends DefaultListController |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - private static $TITLE_MAIN = "%s Tag | Jacob Emerick's Blog"; |
|
| 9 | - private static $DESCRIPTION_MAIN = "Posts tagged with %s on Jacob Emerick's Blog, a website about Upper Peninsula hiking and web development best practices."; |
|
| 8 | + private static $TITLE_MAIN = "%s Tag | Jacob Emerick's Blog"; |
|
| 9 | + private static $DESCRIPTION_MAIN = "Posts tagged with %s on Jacob Emerick's Blog, a website about Upper Peninsula hiking and web development best practices."; |
|
| 10 | 10 | |
| 11 | - private static $TITLE_PAGINATED = "%s - Page %d of %d | Jacob Emerick's Blog"; |
|
| 12 | - private static $DESCRIPTION_PAGINATED = "Page %d of %d with posts tagged with %s on Jacob Emerick's Blog, a website about the hiking and development adventures of a young man."; |
|
| 11 | + private static $TITLE_PAGINATED = "%s - Page %d of %d | Jacob Emerick's Blog"; |
|
| 12 | + private static $DESCRIPTION_PAGINATED = "Page %d of %d with posts tagged with %s on Jacob Emerick's Blog, a website about the hiking and development adventures of a young man."; |
|
| 13 | 13 | |
| 14 | - private static $KEYWORD_ARRAY = array( |
|
| 15 | - 'hiking', |
|
| 16 | - 'web development', |
|
| 17 | - 'blog', |
|
| 18 | - 'Jacob Emerick'); |
|
| 14 | + private static $KEYWORD_ARRAY = array( |
|
| 15 | + 'hiking', |
|
| 16 | + 'web development', |
|
| 17 | + 'blog', |
|
| 18 | + 'Jacob Emerick'); |
|
| 19 | 19 | |
| 20 | - private static $LIST_DESCRIPTION = 'Viewing %d - %d of %d posts tagged with %s.'; |
|
| 20 | + private static $LIST_DESCRIPTION = 'Viewing %d - %d of %d posts tagged with %s.'; |
|
| 21 | 21 | |
| 22 | - private $tag; |
|
| 22 | + private $tag; |
|
| 23 | 23 | |
| 24 | - public function __construct() |
|
| 25 | - { |
|
| 26 | - $tag = URLDecode::getPiece(2); |
|
| 27 | - $tag = str_replace('-', ' ', $tag); |
|
| 24 | + public function __construct() |
|
| 25 | + { |
|
| 26 | + $tag = URLDecode::getPiece(2); |
|
| 27 | + $tag = str_replace('-', ' ', $tag); |
|
| 28 | 28 | |
| 29 | 29 | global $container; |
| 30 | 30 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
| 31 | 31 | $tag_result = $repository->findTagByTitle($tag); |
| 32 | 32 | |
| 33 | - if($tag_result === false) |
|
| 34 | - $this->eject(); |
|
| 33 | + if($tag_result === false) |
|
| 34 | + $this->eject(); |
|
| 35 | 35 | |
| 36 | - $this->tag = $tag_result; |
|
| 36 | + $this->tag = $tag_result; |
|
| 37 | 37 | |
| 38 | - parent::__construct(); |
|
| 39 | - } |
|
| 38 | + parent::__construct(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - protected function set_head_data() |
|
| 42 | - { |
|
| 43 | - parent::set_head_data(); |
|
| 41 | + protected function set_head_data() |
|
| 42 | + { |
|
| 43 | + parent::set_head_data(); |
|
| 44 | 44 | |
| 45 | - if($this->page == 1) |
|
| 46 | - { |
|
| 47 | - $this->set_title(sprintf(self::$TITLE_MAIN, ucwords($this->tag['tag']))); |
|
| 48 | - $this->set_description(sprintf(self::$DESCRIPTION_MAIN, ucwords($this->tag['tag']))); |
|
| 49 | - } |
|
| 50 | - else |
|
| 51 | - { |
|
| 52 | - $this->set_title(sprintf(self::$TITLE_PAGINATED, ucwords($this->tag['tag']), $this->page, $this->total_pages)); |
|
| 53 | - $this->set_description(sprintf(self::$DESCRIPTION_PAGINATED, $this->page, $this->total_pages, ucwords($this->tag['tag']))); |
|
| 54 | - } |
|
| 45 | + if($this->page == 1) |
|
| 46 | + { |
|
| 47 | + $this->set_title(sprintf(self::$TITLE_MAIN, ucwords($this->tag['tag']))); |
|
| 48 | + $this->set_description(sprintf(self::$DESCRIPTION_MAIN, ucwords($this->tag['tag']))); |
|
| 49 | + } |
|
| 50 | + else |
|
| 51 | + { |
|
| 52 | + $this->set_title(sprintf(self::$TITLE_PAGINATED, ucwords($this->tag['tag']), $this->page, $this->total_pages)); |
|
| 53 | + $this->set_description(sprintf(self::$DESCRIPTION_PAGINATED, $this->page, $this->total_pages, ucwords($this->tag['tag']))); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $keyword_array = self::$KEYWORD_ARRAY; |
|
| 57 | - array_unshift($keyword_array, $this->tag['tag']); |
|
| 58 | - $this->set_keywords($keyword_array); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - protected function get_introduction() |
|
| 62 | - { |
|
| 63 | - $tag = ucwords($this->tag['tag']); |
|
| 56 | + $keyword_array = self::$KEYWORD_ARRAY; |
|
| 57 | + array_unshift($keyword_array, $this->tag['tag']); |
|
| 58 | + $this->set_keywords($keyword_array); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + protected function get_introduction() |
|
| 62 | + { |
|
| 63 | + $tag = ucwords($this->tag['tag']); |
|
| 64 | 64 | |
| 65 | - if($this->page == 1) |
|
| 66 | - { |
|
| 65 | + if($this->page == 1) |
|
| 66 | + { |
|
| 67 | 67 | global $container; |
| 68 | 68 | $repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']); |
| 69 | 69 | $introduction_result = $repository->findByType('tag', $this->tag['tag']); |
| 70 | 70 | |
| 71 | - if($introduction_result !== false) |
|
| 72 | - { |
|
| 73 | - $introduction = array(); |
|
| 74 | - $introduction['title'] = $introduction_result['title']; |
|
| 75 | - $introduction['content'] = $introduction_result['content']; |
|
| 76 | - $introduction['image'] = $this->get_introduction_image($introduction_result['image']); |
|
| 71 | + if($introduction_result !== false) |
|
| 72 | + { |
|
| 73 | + $introduction = array(); |
|
| 74 | + $introduction['title'] = $introduction_result['title']; |
|
| 75 | + $introduction['content'] = $introduction_result['content']; |
|
| 76 | + $introduction['image'] = $this->get_introduction_image($introduction_result['image']); |
|
| 77 | 77 | |
| 78 | - return $introduction; |
|
| 79 | - } |
|
| 78 | + return $introduction; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - return array( |
|
| 82 | - 'title' => "Viewing posts about {$tag}."); |
|
| 83 | - } |
|
| 81 | + return array( |
|
| 82 | + 'title' => "Viewing posts about {$tag}."); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return array( |
|
| 86 | - 'title' => "{$tag} posts, page {$this->page} of {$this->total_pages}."); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - protected function get_page_number() |
|
| 90 | - { |
|
| 91 | - $page = URLDecode::getPiece(3); |
|
| 92 | - if(isset($page) && is_numeric($page)) |
|
| 93 | - return $page; |
|
| 94 | - return 1; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - protected function get_list_results() |
|
| 98 | - { |
|
| 85 | + return array( |
|
| 86 | + 'title' => "{$tag} posts, page {$this->page} of {$this->total_pages}."); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + protected function get_page_number() |
|
| 90 | + { |
|
| 91 | + $page = URLDecode::getPiece(3); |
|
| 92 | + if(isset($page) && is_numeric($page)) |
|
| 93 | + return $page; |
|
| 94 | + return 1; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + protected function get_list_results() |
|
| 98 | + { |
|
| 99 | 99 | global $container; |
| 100 | 100 | $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
| 101 | 101 | return $repository->getActivePostsByTag($this->tag['id'], self::$POSTS_PER_PAGE, $this->offset); |
| 102 | - } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - protected function get_list_description() |
|
| 105 | - { |
|
| 106 | - $start = $this->offset + 1; |
|
| 107 | - $end = min($this->offset + self::$POSTS_PER_PAGE, $this->get_total_post_count()); |
|
| 104 | + protected function get_list_description() |
|
| 105 | + { |
|
| 106 | + $start = $this->offset + 1; |
|
| 107 | + $end = min($this->offset + self::$POSTS_PER_PAGE, $this->get_total_post_count()); |
|
| 108 | 108 | |
| 109 | - return sprintf(self::$LIST_DESCRIPTION, $start, $end, $this->get_total_post_count(), $this->tag['tag']); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - protected function get_list_next_link() |
|
| 113 | - { |
|
| 114 | - if($this->page == 1) |
|
| 115 | - return; |
|
| 116 | - if($this->page == 2) |
|
| 117 | - return Content::instance('URLSafe', "/tag/{$this->tag['tag']}/")->activate(); |
|
| 118 | - return Content::instance('URLSafe', "/tag/{$this->tag['tag']}/" . ($this->page - 1) . '/')->activate(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - protected function get_list_prev_link() |
|
| 122 | - { |
|
| 123 | - if(($this->page * self::$POSTS_PER_PAGE) >= $this->get_total_post_count()) |
|
| 124 | - return; |
|
| 125 | - return Content::instance('URLSafe', "/tag/{$this->tag['tag']}/" . ($this->page + 1) . '/')->activate(); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - private $total_post_count; |
|
| 129 | - protected function get_total_post_count() |
|
| 130 | - { |
|
| 131 | - if(!isset($this->total_post_count)) { |
|
| 109 | + return sprintf(self::$LIST_DESCRIPTION, $start, $end, $this->get_total_post_count(), $this->tag['tag']); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + protected function get_list_next_link() |
|
| 113 | + { |
|
| 114 | + if($this->page == 1) |
|
| 115 | + return; |
|
| 116 | + if($this->page == 2) |
|
| 117 | + return Content::instance('URLSafe', "/tag/{$this->tag['tag']}/")->activate(); |
|
| 118 | + return Content::instance('URLSafe', "/tag/{$this->tag['tag']}/" . ($this->page - 1) . '/')->activate(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + protected function get_list_prev_link() |
|
| 122 | + { |
|
| 123 | + if(($this->page * self::$POSTS_PER_PAGE) >= $this->get_total_post_count()) |
|
| 124 | + return; |
|
| 125 | + return Content::instance('URLSafe', "/tag/{$this->tag['tag']}/" . ($this->page + 1) . '/')->activate(); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + private $total_post_count; |
|
| 129 | + protected function get_total_post_count() |
|
| 130 | + { |
|
| 131 | + if(!isset($this->total_post_count)) { |
|
| 132 | 132 | global $container; |
| 133 | 133 | $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
| 134 | 134 | $this->total_post_count = $repository->getActivePostsCountByTag($this->tag['id']); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return $this->total_post_count; |
|
| 138 | - } |
|
| 137 | + return $this->total_post_count; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
@@ -6,191 +6,191 @@ discard block |
||
| 6 | 6 | final class PostController extends DefaultPageController |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - private static $PAGE_DESCRIPTION_LIMIT = 250; |
|
| 9 | + private static $PAGE_DESCRIPTION_LIMIT = 250; |
|
| 10 | 10 | |
| 11 | - private static $TITLE = "%s | Jacob Emerick's Blog"; |
|
| 12 | - private static $AUTHOR = 'Jacob Emerick'; |
|
| 13 | - private static $AUTHOR_URL = 'https://home.jacobemerick.com/'; |
|
| 11 | + private static $TITLE = "%s | Jacob Emerick's Blog"; |
|
| 12 | + private static $AUTHOR = 'Jacob Emerick'; |
|
| 13 | + private static $AUTHOR_URL = 'https://home.jacobemerick.com/'; |
|
| 14 | 14 | |
| 15 | - private static $POST_LENGTH_SHORT = 100; |
|
| 16 | - private static $POST_LENGTH_LONG = 140; |
|
| 15 | + private static $POST_LENGTH_SHORT = 100; |
|
| 16 | + private static $POST_LENGTH_LONG = 140; |
|
| 17 | 17 | |
| 18 | - private $post; |
|
| 19 | - private $tags; |
|
| 20 | - private $comment_errors = array(); |
|
| 18 | + private $post; |
|
| 19 | + private $tags; |
|
| 20 | + private $comment_errors = array(); |
|
| 21 | 21 | |
| 22 | - public function __construct() |
|
| 23 | - { |
|
| 24 | - parent::__construct(); |
|
| 22 | + public function __construct() |
|
| 23 | + { |
|
| 24 | + parent::__construct(); |
|
| 25 | 25 | |
| 26 | 26 | global $container; |
| 27 | 27 | $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
| 28 | 28 | $this->post = $repository->findPostByPath(URLDecode::getPiece(2)); |
| 29 | 29 | |
| 30 | - if($this->post == null) |
|
| 31 | - $this->eject(); |
|
| 30 | + if($this->post == null) |
|
| 31 | + $this->eject(); |
|
| 32 | 32 | |
| 33 | - $this->handle_comment_submit( |
|
| 34 | - self::$BLOG_SITE_ID, |
|
| 35 | - $this->post['path'], |
|
| 36 | - Loader::getRootUrl('blog') . $this->post['category'] . '/' . $this->post['path'] . '/', |
|
| 37 | - $this->post['title']); |
|
| 33 | + $this->handle_comment_submit( |
|
| 34 | + self::$BLOG_SITE_ID, |
|
| 35 | + $this->post['path'], |
|
| 36 | + Loader::getRootUrl('blog') . $this->post['category'] . '/' . $this->post['path'] . '/', |
|
| 37 | + $this->post['title']); |
|
| 38 | 38 | |
| 39 | 39 | global $container; |
| 40 | 40 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
| 41 | 41 | $this->tags = $repository->getTagsForPost($this->post['id']); |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - protected function set_head_data() |
|
| 45 | - { |
|
| 46 | - parent::set_head_data(); |
|
| 44 | + protected function set_head_data() |
|
| 45 | + { |
|
| 46 | + parent::set_head_data(); |
|
| 47 | 47 | |
| 48 | - $this->set_title(sprintf(self::$TITLE, $this->post['title'])); |
|
| 49 | - $this->set_description($this->get_post_description()); |
|
| 50 | - $this->set_keywords($this->get_post_keywords()); |
|
| 51 | - $this->set_author(self::$AUTHOR); |
|
| 48 | + $this->set_title(sprintf(self::$TITLE, $this->post['title'])); |
|
| 49 | + $this->set_description($this->get_post_description()); |
|
| 50 | + $this->set_keywords($this->get_post_keywords()); |
|
| 51 | + $this->set_author(self::$AUTHOR); |
|
| 52 | 52 | |
| 53 | 53 | $photo = Content::instance('FetchFirstPhoto', $this->post['body'])->activate(true); |
| 54 | 54 | $photo = preg_match('/^<img src="([a-z-:\.\/]+)" [^>]+>$/', $photo, $matches); |
| 55 | 55 | $this->set_head('thumbnail', $matches[1]); |
| 56 | 56 | |
| 57 | - if (array_key_exists($this->post['id'], self::$DEPRECATED_BLOGS)) { |
|
| 58 | - $log_id = self::$DEPRECATED_BLOGS[$this->post['id']]; |
|
| 59 | - $log = LogCollector::getById($log_id); |
|
| 60 | - if (!empty($log)) { |
|
| 61 | - $log_url = Loader::getRootUrl('waterfalls') . "journal/{$log->alias}/"; |
|
| 62 | - $this->set_canonical($log_url); |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 57 | + if (array_key_exists($this->post['id'], self::$DEPRECATED_BLOGS)) { |
|
| 58 | + $log_id = self::$DEPRECATED_BLOGS[$this->post['id']]; |
|
| 59 | + $log = LogCollector::getById($log_id); |
|
| 60 | + if (!empty($log)) { |
|
| 61 | + $log_url = Loader::getRootUrl('waterfalls') . "journal/{$log->alias}/"; |
|
| 62 | + $this->set_canonical($log_url); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - protected function get_introduction() {} |
|
| 67 | + protected function get_introduction() {} |
|
| 68 | 68 | |
| 69 | - protected function set_body_data() |
|
| 70 | - { |
|
| 71 | - parent::set_body_data(); |
|
| 69 | + protected function set_body_data() |
|
| 70 | + { |
|
| 71 | + parent::set_body_data(); |
|
| 72 | 72 | |
| 73 | - $this->set_body('title', $this->post['title']); |
|
| 74 | - $this->set_body('view', 'Post'); |
|
| 75 | - $this->set_body('data', array( |
|
| 76 | - 'post' => $this->format_post($this->post, false), |
|
| 77 | - 'series_posts' => $this->get_series_posts(), |
|
| 78 | - 'related_posts' => $this->get_related_posts(), |
|
| 79 | - 'author' => self::$AUTHOR, |
|
| 80 | - 'author_url' => self::$AUTHOR_URL, |
|
| 81 | - 'comment_array' => $this->get_comment_array("{$this->post['category']}/{$this->post['path']}"), |
|
| 73 | + $this->set_body('title', $this->post['title']); |
|
| 74 | + $this->set_body('view', 'Post'); |
|
| 75 | + $this->set_body('data', array( |
|
| 76 | + 'post' => $this->format_post($this->post, false), |
|
| 77 | + 'series_posts' => $this->get_series_posts(), |
|
| 78 | + 'related_posts' => $this->get_related_posts(), |
|
| 79 | + 'author' => self::$AUTHOR, |
|
| 80 | + 'author_url' => self::$AUTHOR_URL, |
|
| 81 | + 'comment_array' => $this->get_comment_array("{$this->post['category']}/{$this->post['path']}"), |
|
| 82 | 82 | )); |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - protected function get_post_description() |
|
| 86 | - { |
|
| 87 | - $description = $this->post['body']; |
|
| 88 | - $description = strip_tags($description); |
|
| 89 | - $description = Content::instance('SmartTrim', $description)->activate(self::$PAGE_DESCRIPTION_LIMIT); |
|
| 85 | + protected function get_post_description() |
|
| 86 | + { |
|
| 87 | + $description = $this->post['body']; |
|
| 88 | + $description = strip_tags($description); |
|
| 89 | + $description = Content::instance('SmartTrim', $description)->activate(self::$PAGE_DESCRIPTION_LIMIT); |
|
| 90 | 90 | |
| 91 | - return $description; |
|
| 92 | - } |
|
| 91 | + return $description; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - protected function get_post_keywords() |
|
| 95 | - { |
|
| 96 | - $keyword_array = array(); |
|
| 97 | - $keywords = $this->tags; |
|
| 94 | + protected function get_post_keywords() |
|
| 95 | + { |
|
| 96 | + $keyword_array = array(); |
|
| 97 | + $keywords = $this->tags; |
|
| 98 | 98 | |
| 99 | - foreach($keywords as $keyword) |
|
| 100 | - { |
|
| 101 | - $keyword_array[] = $keyword['tag']; |
|
| 102 | - } |
|
| 99 | + foreach($keywords as $keyword) |
|
| 100 | + { |
|
| 101 | + $keyword_array[] = $keyword['tag']; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $keyword_array[] = 'blog'; |
|
| 105 | - $keyword_array[] = 'Jacob Emerick'; |
|
| 104 | + $keyword_array[] = 'blog'; |
|
| 105 | + $keyword_array[] = 'Jacob Emerick'; |
|
| 106 | 106 | |
| 107 | - return $keyword_array; |
|
| 108 | - } |
|
| 107 | + return $keyword_array; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - private function get_series_posts() |
|
| 111 | - { |
|
| 112 | - $series_posts = $this->fetch_series_posts(); |
|
| 113 | - if(count($series_posts) < 1) |
|
| 114 | - return array(); |
|
| 110 | + private function get_series_posts() |
|
| 111 | + { |
|
| 112 | + $series_posts = $this->fetch_series_posts(); |
|
| 113 | + if(count($series_posts) < 1) |
|
| 114 | + return array(); |
|
| 115 | 115 | |
| 116 | - $previous_post = new stdclass(); |
|
| 117 | - $next_post = new stdclass(); |
|
| 116 | + $previous_post = new stdclass(); |
|
| 117 | + $next_post = new stdclass(); |
|
| 118 | 118 | |
| 119 | - $found_current_post = false; |
|
| 120 | - foreach($series_posts as $post_row) |
|
| 121 | - { |
|
| 122 | - if($post_row['post'] == $this->post['id']) |
|
| 123 | - { |
|
| 124 | - $found_current_post = true; |
|
| 125 | - continue; |
|
| 126 | - } |
|
| 119 | + $found_current_post = false; |
|
| 120 | + foreach($series_posts as $post_row) |
|
| 121 | + { |
|
| 122 | + if($post_row['post'] == $this->post['id']) |
|
| 123 | + { |
|
| 124 | + $found_current_post = true; |
|
| 125 | + continue; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - $post = new stdclass(); |
|
| 128 | + $post = new stdclass(); |
|
| 129 | 129 | |
| 130 | - if ( |
|
| 130 | + if ( |
|
| 131 | 131 | strpos($post_row['title'], 'Rainy Supe Loop') === 0 || |
| 132 | 132 | strpos($post_row['title'], 'Malapais Loop') === 0 || |
| 133 | 133 | strpos($post_row['title'], 'Mazatzal Peak Loop') === 0 || |
| 134 | 134 | strpos($post_row['title'], 'Dripping Springs Loop') === 0 |
| 135 | - ) { |
|
| 135 | + ) { |
|
| 136 | 136 | $title = $post_row['title']; |
| 137 | 137 | $title = explode(':', $title); |
| 138 | 138 | $title = array_pop($title); |
| 139 | 139 | $title = trim($title); |
| 140 | 140 | $post->title = $title; |
| 141 | - } else if (strpos($post_row['title'], 'Isle Royale') === 0) { |
|
| 142 | - $title = $post_row['title']; |
|
| 143 | - $title = explode(',', $title); |
|
| 144 | - $title = array_pop($title); |
|
| 145 | - $title = trim($title); |
|
| 146 | - $post->title = $title; |
|
| 147 | - } else { |
|
| 148 | - $post->title = $post_row['title']; |
|
| 149 | - } |
|
| 141 | + } else if (strpos($post_row['title'], 'Isle Royale') === 0) { |
|
| 142 | + $title = $post_row['title']; |
|
| 143 | + $title = explode(',', $title); |
|
| 144 | + $title = array_pop($title); |
|
| 145 | + $title = trim($title); |
|
| 146 | + $post->title = $title; |
|
| 147 | + } else { |
|
| 148 | + $post->title = $post_row['title']; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $post->url = Loader::getRootUrl('blog') . "{$post_row['category']}/{$post_row['path']}/"; |
|
| 151 | + $post->url = Loader::getRootUrl('blog') . "{$post_row['category']}/{$post_row['path']}/"; |
|
| 152 | 152 | |
| 153 | - if(!$found_current_post) |
|
| 154 | - $previous_post = $post; |
|
| 155 | - else |
|
| 156 | - { |
|
| 157 | - $next_post = $post; |
|
| 158 | - break; |
|
| 159 | - } |
|
| 160 | - } |
|
| 153 | + if(!$found_current_post) |
|
| 154 | + $previous_post = $post; |
|
| 155 | + else |
|
| 156 | + { |
|
| 157 | + $next_post = $post; |
|
| 158 | + break; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return array( |
|
| 163 | - 'title' => $post_row['series_title'], |
|
| 164 | - 'description' => Content::instance('FixInternalLink', $post_row['series_description'])->activate(), |
|
| 165 | - 'previous' => $previous_post, |
|
| 166 | - 'next' => $next_post); |
|
| 167 | - } |
|
| 162 | + return array( |
|
| 163 | + 'title' => $post_row['series_title'], |
|
| 164 | + 'description' => Content::instance('FixInternalLink', $post_row['series_description'])->activate(), |
|
| 165 | + 'previous' => $previous_post, |
|
| 166 | + 'next' => $next_post); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - private $series_posts; |
|
| 170 | - private function fetch_series_posts() |
|
| 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; |
|
| 178 | - } |
|
| 169 | + private $series_posts; |
|
| 170 | + private function fetch_series_posts() |
|
| 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; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - private function get_related_posts() |
|
| 181 | - { |
|
| 182 | - $tag_array = array(); |
|
| 183 | - foreach($this->tags as $tag) |
|
| 184 | - { |
|
| 185 | - $tag_array[] = $tag['id']; |
|
| 186 | - } |
|
| 180 | + private function get_related_posts() |
|
| 181 | + { |
|
| 182 | + $tag_array = array(); |
|
| 183 | + foreach($this->tags as $tag) |
|
| 184 | + { |
|
| 185 | + $tag_array[] = $tag['id']; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - $series_posts = $this->fetch_series_posts(); |
|
| 189 | - $exclude_post_array = array(); |
|
| 190 | - foreach($series_posts as $series_post) |
|
| 191 | - { |
|
| 192 | - $exclude_post_array[] = $series_post['post']; |
|
| 193 | - } |
|
| 188 | + $series_posts = $this->fetch_series_posts(); |
|
| 189 | + $exclude_post_array = array(); |
|
| 190 | + foreach($series_posts as $series_post) |
|
| 191 | + { |
|
| 192 | + $exclude_post_array[] = $series_post['post']; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | global $container; |
| 196 | 196 | $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
@@ -198,20 +198,20 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | $post_array = array(); |
| 200 | 200 | |
| 201 | - foreach($post_result as $post_row) |
|
| 202 | - { |
|
| 203 | - $post = new stdclass(); |
|
| 204 | - $post->title = $post_row['title']; |
|
| 205 | - $post->url = Loader::getRootUrl('blog') . "{$post_row['category']}/{$post_row['path']}/"; |
|
| 206 | - $post->category = ucwords(str_replace('-', ' ', $post_row['category'])); |
|
| 207 | - $post->thumb = Content::instance('FetchFirstPhoto', $post_row['body'])->activate(); |
|
| 208 | - $post->body = Content::instance('SmartTrim', $post_row['body'])->activate(($post->thumb !== '') ? self::$POST_LENGTH_SHORT : self::$POST_LENGTH_LONG); |
|
| 201 | + foreach($post_result as $post_row) |
|
| 202 | + { |
|
| 203 | + $post = new stdclass(); |
|
| 204 | + $post->title = $post_row['title']; |
|
| 205 | + $post->url = Loader::getRootUrl('blog') . "{$post_row['category']}/{$post_row['path']}/"; |
|
| 206 | + $post->category = ucwords(str_replace('-', ' ', $post_row['category'])); |
|
| 207 | + $post->thumb = Content::instance('FetchFirstPhoto', $post_row['body'])->activate(); |
|
| 208 | + $post->body = Content::instance('SmartTrim', $post_row['body'])->activate(($post->thumb !== '') ? self::$POST_LENGTH_SHORT : self::$POST_LENGTH_LONG); |
|
| 209 | 209 | |
| 210 | - $post_array[] = $post; |
|
| 211 | - } |
|
| 210 | + $post_array[] = $post; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - return $post_array; |
|
| 214 | - } |
|
| 213 | + return $post_array; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | 216 | protected function get_comment_array($path) |
| 217 | 217 | { |
@@ -5,64 +5,64 @@ |
||
| 5 | 5 | abstract class DefaultListController extends DefaultPageController |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - protected static $POSTS_PER_PAGE = 10; |
|
| 8 | + protected static $POSTS_PER_PAGE = 10; |
|
| 9 | 9 | |
| 10 | - protected $page; |
|
| 11 | - protected $offset; |
|
| 10 | + protected $page; |
|
| 11 | + protected $offset; |
|
| 12 | 12 | |
| 13 | - public function __construct() |
|
| 14 | - { |
|
| 15 | - parent::__construct(); |
|
| 13 | + public function __construct() |
|
| 14 | + { |
|
| 15 | + parent::__construct(); |
|
| 16 | 16 | |
| 17 | - $this->page = $this->get_page_number(); |
|
| 18 | - $this->total_pages = ceil($this->get_total_post_count() / self::$POSTS_PER_PAGE); |
|
| 19 | - $this->offset = ($this->page - 1) * self::$POSTS_PER_PAGE; |
|
| 20 | - } |
|
| 17 | + $this->page = $this->get_page_number(); |
|
| 18 | + $this->total_pages = ceil($this->get_total_post_count() / self::$POSTS_PER_PAGE); |
|
| 19 | + $this->offset = ($this->page - 1) * self::$POSTS_PER_PAGE; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - abstract protected function get_page_number(); |
|
| 23 | - abstract protected function get_list_results(); |
|
| 24 | - abstract protected function get_list_description(); |
|
| 25 | - abstract protected function get_list_next_link(); |
|
| 26 | - abstract protected function get_list_prev_link(); |
|
| 27 | - abstract protected function get_total_post_count(); |
|
| 22 | + abstract protected function get_page_number(); |
|
| 23 | + abstract protected function get_list_results(); |
|
| 24 | + abstract protected function get_list_description(); |
|
| 25 | + abstract protected function get_list_next_link(); |
|
| 26 | + abstract protected function get_list_prev_link(); |
|
| 27 | + abstract protected function get_total_post_count(); |
|
| 28 | 28 | |
| 29 | - protected function set_head_data() |
|
| 30 | - { |
|
| 31 | - parent::set_head_data(); |
|
| 29 | + protected function set_head_data() |
|
| 30 | + { |
|
| 31 | + parent::set_head_data(); |
|
| 32 | 32 | |
| 33 | - $this->set_head('next_link', $this->get_list_next_link()); |
|
| 34 | - $this->set_head('previous_link', $this->get_list_prev_link()); |
|
| 35 | - } |
|
| 33 | + $this->set_head('next_link', $this->get_list_next_link()); |
|
| 34 | + $this->set_head('previous_link', $this->get_list_prev_link()); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - protected function set_body_data() |
|
| 38 | - { |
|
| 39 | - parent::set_body_data(); |
|
| 37 | + protected function set_body_data() |
|
| 38 | + { |
|
| 39 | + parent::set_body_data(); |
|
| 40 | 40 | |
| 41 | - $this->set_body('view', 'Listing'); |
|
| 42 | - $this->set_body('data', $this->get_list_body_data()); |
|
| 43 | - } |
|
| 41 | + $this->set_body('view', 'Listing'); |
|
| 42 | + $this->set_body('data', $this->get_list_body_data()); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - final private function get_list_body_data() |
|
| 46 | - { |
|
| 47 | - return array( |
|
| 48 | - 'posts' => $this->get_list_posts(), |
|
| 49 | - 'show_top_navigation' => ($this->page !== 1), |
|
| 50 | - 'navigation' => array( |
|
| 51 | - 'description' => $this->get_list_description(), |
|
| 52 | - 'next' => $this->get_list_next_link(), |
|
| 53 | - 'prev' => $this->get_list_prev_link())); |
|
| 54 | - } |
|
| 45 | + final private function get_list_body_data() |
|
| 46 | + { |
|
| 47 | + return array( |
|
| 48 | + 'posts' => $this->get_list_posts(), |
|
| 49 | + 'show_top_navigation' => ($this->page !== 1), |
|
| 50 | + 'navigation' => array( |
|
| 51 | + 'description' => $this->get_list_description(), |
|
| 52 | + 'next' => $this->get_list_next_link(), |
|
| 53 | + 'prev' => $this->get_list_prev_link())); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - final private function get_list_posts() |
|
| 57 | - { |
|
| 58 | - $post_array = array(); |
|
| 59 | - foreach($this->get_list_results() as $post) |
|
| 60 | - { |
|
| 61 | - $post_array[] = $this->format_post($post, true); |
|
| 62 | - } |
|
| 63 | - if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 64 | - $this->eject(); |
|
| 65 | - return $post_array; |
|
| 66 | - } |
|
| 56 | + final private function get_list_posts() |
|
| 57 | + { |
|
| 58 | + $post_array = array(); |
|
| 59 | + foreach($this->get_list_results() as $post) |
|
| 60 | + { |
|
| 61 | + $post_array[] = $this->format_post($post, true); |
|
| 62 | + } |
|
| 63 | + if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 64 | + $this->eject(); |
|
| 65 | + return $post_array; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -6,134 +6,134 @@ |
||
| 6 | 6 | final class SearchController extends DefaultListController |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - private static $TITLE_MAIN = "%s Search | Jacob Emerick's Blog"; |
|
| 10 | - private static $DESCRIPTION_MAIN = "Posts containing the phrase %s on Jacob Emerick's Blog."; |
|
| 11 | - |
|
| 12 | - private static $TITLE_PAGINATED = "%s Search - Page %d of %d | Jacob Emerick's Blog"; |
|
| 13 | - private static $DESCRIPTION_PAGINATED = "Page %d of %d with posts containing the phrase %s on Jacob Emerick's Blog."; |
|
| 14 | - |
|
| 15 | - private static $KEYWORD_ARRAY = array( |
|
| 16 | - 'hiking', |
|
| 17 | - 'web development', |
|
| 18 | - 'blog', |
|
| 19 | - 'Jacob Emerick'); |
|
| 20 | - |
|
| 21 | - private static $LIST_DESCRIPTION = 'Viewing %d - %d of %d posts containing the phrase %s.'; |
|
| 22 | - private static $SEARCH_WEIGHTS = array( |
|
| 23 | - array( |
|
| 24 | - 'field' => 'title', |
|
| 25 | - 'weight' => 8), |
|
| 26 | - array( |
|
| 27 | - 'field' => 'body', |
|
| 28 | - 'weight' => 4)); |
|
| 29 | - |
|
| 30 | - private $query; |
|
| 31 | - |
|
| 32 | - public function __construct() |
|
| 33 | - { |
|
| 34 | - $query = URLDecode::getPiece(2); |
|
| 35 | - $query = urldecode($query); |
|
| 9 | + private static $TITLE_MAIN = "%s Search | Jacob Emerick's Blog"; |
|
| 10 | + private static $DESCRIPTION_MAIN = "Posts containing the phrase %s on Jacob Emerick's Blog."; |
|
| 11 | + |
|
| 12 | + private static $TITLE_PAGINATED = "%s Search - Page %d of %d | Jacob Emerick's Blog"; |
|
| 13 | + private static $DESCRIPTION_PAGINATED = "Page %d of %d with posts containing the phrase %s on Jacob Emerick's Blog."; |
|
| 14 | + |
|
| 15 | + private static $KEYWORD_ARRAY = array( |
|
| 16 | + 'hiking', |
|
| 17 | + 'web development', |
|
| 18 | + 'blog', |
|
| 19 | + 'Jacob Emerick'); |
|
| 20 | + |
|
| 21 | + private static $LIST_DESCRIPTION = 'Viewing %d - %d of %d posts containing the phrase %s.'; |
|
| 22 | + private static $SEARCH_WEIGHTS = array( |
|
| 23 | + array( |
|
| 24 | + 'field' => 'title', |
|
| 25 | + 'weight' => 8), |
|
| 26 | + array( |
|
| 27 | + 'field' => 'body', |
|
| 28 | + 'weight' => 4)); |
|
| 29 | + |
|
| 30 | + private $query; |
|
| 31 | + |
|
| 32 | + public function __construct() |
|
| 33 | + { |
|
| 34 | + $query = URLDecode::getPiece(2); |
|
| 35 | + $query = urldecode($query); |
|
| 36 | 36 | $query = str_replace('-', ' ', $query); |
| 37 | 37 | |
| 38 | - $this->query = $query; |
|
| 38 | + $this->query = $query; |
|
| 39 | 39 | |
| 40 | - parent::__construct(); |
|
| 41 | - } |
|
| 40 | + parent::__construct(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - protected function set_head_data() |
|
| 44 | - { |
|
| 45 | - parent::set_head_data(); |
|
| 43 | + protected function set_head_data() |
|
| 44 | + { |
|
| 45 | + parent::set_head_data(); |
|
| 46 | 46 | |
| 47 | - if($this->page == 1) |
|
| 48 | - { |
|
| 49 | - $this->set_title(sprintf(self::$TITLE_MAIN, ucwords($this->query))); |
|
| 50 | - $this->set_description(sprintf(self::$DESCRIPTION_MAIN, ucwords($this->query))); |
|
| 51 | - } |
|
| 52 | - else |
|
| 53 | - { |
|
| 54 | - $this->set_title(sprintf(self::$TITLE_PAGINATED, ucwords($this->query), $this->page, $this->total_pages)); |
|
| 55 | - $this->set_description(sprintf(self::$DESCRIPTION_PAGINATED, $this->page, $this->total_pages, ucwords($this->query))); |
|
| 56 | - } |
|
| 47 | + if($this->page == 1) |
|
| 48 | + { |
|
| 49 | + $this->set_title(sprintf(self::$TITLE_MAIN, ucwords($this->query))); |
|
| 50 | + $this->set_description(sprintf(self::$DESCRIPTION_MAIN, ucwords($this->query))); |
|
| 51 | + } |
|
| 52 | + else |
|
| 53 | + { |
|
| 54 | + $this->set_title(sprintf(self::$TITLE_PAGINATED, ucwords($this->query), $this->page, $this->total_pages)); |
|
| 55 | + $this->set_description(sprintf(self::$DESCRIPTION_PAGINATED, $this->page, $this->total_pages, ucwords($this->query))); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $keyword_array = self::$KEYWORD_ARRAY; |
|
| 59 | - array_unshift($keyword_array, $this->query); |
|
| 60 | - $this->set_keywords($keyword_array); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - protected function get_introduction() |
|
| 64 | - { |
|
| 65 | - if($this->total_pages > 1) |
|
| 66 | - return array( |
|
| 67 | - 'title' => "Posts from search '{$this->query}', page {$this->page} of {$this->total_pages}."); |
|
| 68 | - else if($this->total_pages == 1) |
|
| 69 | - return array( |
|
| 70 | - 'title' => "Posts from search '{$this->query}'."); |
|
| 71 | - else |
|
| 72 | - return array( |
|
| 73 | - 'title' => "Sorry, '{$this->query}' didn't return any posts."); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - protected function get_page_number() |
|
| 77 | - { |
|
| 78 | - $page = URLDecode::getPiece(3); |
|
| 79 | - if(isset($page) && is_numeric($page)) |
|
| 80 | - return $page; |
|
| 81 | - return 1; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - private $search_result; |
|
| 85 | - private function get_search_result() |
|
| 86 | - { |
|
| 87 | - if(!isset($this->search_result)) |
|
| 88 | - { |
|
| 58 | + $keyword_array = self::$KEYWORD_ARRAY; |
|
| 59 | + array_unshift($keyword_array, $this->query); |
|
| 60 | + $this->set_keywords($keyword_array); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + protected function get_introduction() |
|
| 64 | + { |
|
| 65 | + if($this->total_pages > 1) |
|
| 66 | + return array( |
|
| 67 | + 'title' => "Posts from search '{$this->query}', page {$this->page} of {$this->total_pages}."); |
|
| 68 | + else if($this->total_pages == 1) |
|
| 69 | + return array( |
|
| 70 | + 'title' => "Posts from search '{$this->query}'."); |
|
| 71 | + else |
|
| 72 | + return array( |
|
| 73 | + 'title' => "Sorry, '{$this->query}' didn't return any posts."); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + protected function get_page_number() |
|
| 77 | + { |
|
| 78 | + $page = URLDecode::getPiece(3); |
|
| 79 | + if(isset($page) && is_numeric($page)) |
|
| 80 | + return $page; |
|
| 81 | + return 1; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + private $search_result; |
|
| 85 | + private function get_search_result() |
|
| 86 | + { |
|
| 87 | + if(!isset($this->search_result)) |
|
| 88 | + { |
|
| 89 | 89 | global $container; |
| 90 | 90 | $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
| 91 | 91 | $posts = $repository->getActivePosts(); |
| 92 | 92 | |
| 93 | - $this->search_result = Search::instance() |
|
| 94 | - ->setQuery($this->query) |
|
| 95 | - ->setResult($posts) |
|
| 96 | - ->setWeight(self::$SEARCH_WEIGHTS) |
|
| 97 | - ->perform(); |
|
| 98 | - } |
|
| 99 | - return $this->search_result; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - protected function get_list_results() |
|
| 103 | - { |
|
| 104 | - return array_slice($this->get_search_result(), $this->offset, self::$POSTS_PER_PAGE); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - protected function get_list_description() |
|
| 108 | - { |
|
| 109 | - $start = $this->offset + 1; |
|
| 110 | - $end = min($this->offset + self::$POSTS_PER_PAGE, $this->get_total_post_count()); |
|
| 93 | + $this->search_result = Search::instance() |
|
| 94 | + ->setQuery($this->query) |
|
| 95 | + ->setResult($posts) |
|
| 96 | + ->setWeight(self::$SEARCH_WEIGHTS) |
|
| 97 | + ->perform(); |
|
| 98 | + } |
|
| 99 | + return $this->search_result; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + protected function get_list_results() |
|
| 103 | + { |
|
| 104 | + return array_slice($this->get_search_result(), $this->offset, self::$POSTS_PER_PAGE); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + protected function get_list_description() |
|
| 108 | + { |
|
| 109 | + $start = $this->offset + 1; |
|
| 110 | + $end = min($this->offset + self::$POSTS_PER_PAGE, $this->get_total_post_count()); |
|
| 111 | 111 | |
| 112 | - return sprintf(self::$LIST_DESCRIPTION, $start, $end, $this->get_total_post_count(), $this->query); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - protected function get_list_next_link() |
|
| 116 | - { |
|
| 117 | - if($this->page == 1) |
|
| 118 | - return; |
|
| 119 | - if($this->page == 2) |
|
| 120 | - return Content::instance('URLSafe', "/search/{$this->query}/")->activate(); |
|
| 121 | - return Content::instance('URLSafe', "/search/{$this->query}/" . ($this->page - 1) . '/')->activate(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - protected function get_list_prev_link() |
|
| 125 | - { |
|
| 126 | - if(($this->page * self::$POSTS_PER_PAGE) >= $this->get_total_post_count()) |
|
| 127 | - return; |
|
| 128 | - return Content::instance('URLSafe', "/search/{$this->query}/" . ($this->page + 1) . '/')->activate(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - private $total_post_count; |
|
| 132 | - protected function get_total_post_count() |
|
| 133 | - { |
|
| 134 | - if(!isset($this->total_post_count)) |
|
| 135 | - $this->total_post_count = count($this->get_search_result()); |
|
| 136 | - return $this->total_post_count; |
|
| 137 | - } |
|
| 112 | + return sprintf(self::$LIST_DESCRIPTION, $start, $end, $this->get_total_post_count(), $this->query); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + protected function get_list_next_link() |
|
| 116 | + { |
|
| 117 | + if($this->page == 1) |
|
| 118 | + return; |
|
| 119 | + if($this->page == 2) |
|
| 120 | + return Content::instance('URLSafe', "/search/{$this->query}/")->activate(); |
|
| 121 | + return Content::instance('URLSafe', "/search/{$this->query}/" . ($this->page - 1) . '/')->activate(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + protected function get_list_prev_link() |
|
| 125 | + { |
|
| 126 | + if(($this->page * self::$POSTS_PER_PAGE) >= $this->get_total_post_count()) |
|
| 127 | + return; |
|
| 128 | + return Content::instance('URLSafe', "/search/{$this->query}/" . ($this->page + 1) . '/')->activate(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + private $total_post_count; |
|
| 132 | + protected function get_total_post_count() |
|
| 133 | + { |
|
| 134 | + if(!isset($this->total_post_count)) |
|
| 135 | + $this->total_post_count = count($this->get_search_result()); |
|
| 136 | + return $this->total_post_count; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } |
@@ -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 | - } |
|
| 33 | - |
|
| 34 | - protected function get_introduction() |
|
| 35 | - { |
|
| 36 | - return; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - protected function get_introduction_image($id) |
|
| 40 | - { |
|
| 41 | - Loader::load('collector', 'image/PhotoCollector'); |
|
| 42 | - $photo_result = PhotoCollector::getRow($id); |
|
| 30 | + $this->add_css('normalize'); |
|
| 31 | + $this->add_css('blog'); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + protected function get_introduction() |
|
| 35 | + { |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | + |
|
| 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 | - } |
|
| 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()); |
|
| 54 | + return sprintf(self::$INTRODUCTION_IMAGE_PATTERN, $category, $name, $size, $height, $width, $description); |
|
| 55 | + } |
|
| 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()); |
|
| 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']); |
|
| 79 | - |
|
| 80 | - return $post_object; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - final private function get_comments_for_post($post) |
|
| 84 | - { |
|
| 85 | - $count = CommentCollector::getCommentCountForURL(self::$BLOG_SITE_ID, $post['path']); |
|
| 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 | + |
|
| 80 | + return $post_object; |
|
| 81 | + } |
|
| 82 | + |
|
| 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 | - } |
|
| 146 | - |
|
| 147 | - final private function get_body_for_post($post, $trim) |
|
| 148 | - { |
|
| 149 | - $body = $post['body']; |
|
| 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 | + |
|
| 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 | - } |
|
| 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 | - } |
|
| 167 | - |
|
| 168 | - final private function get_tag_cloud() |
|
| 169 | - { |
|
| 157 | + return $body; |
|
| 158 | + } |
|
| 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 | + } |
|
| 167 | + |
|
| 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 | - } |
|
| 203 | - |
|
| 204 | - final private function get_comments() |
|
| 205 | - { |
|
| 206 | - $comment_array = CommentCollector::getRecentBlogComments(self::$RECENT_COMMENT_COUNT); |
|
| 196 | + foreach($tag_result as $tag) |
|
| 197 | + { |
|
| 198 | + if($tag['count'] > $maximum) |
|
| 199 | + $maximum = $tag['count']; |
|
| 200 | + } |
|
| 201 | + return $maximum; |
|
| 202 | + } |
|
| 203 | + |
|
| 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 | { |
@@ -5,47 +5,47 @@ |
||
| 5 | 5 | final class AboutController extends DefaultPageController |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - private static $TITLE = 'About the Blog | Jacob Emerick'; |
|
| 9 | - private static $DESCRIPTION = "A little bit about the awesomeness on Jacob Emerick's Blog, diving into the topics covered, technology used, and methodology of writing new posts."; |
|
| 10 | - |
|
| 11 | - private static $KEYWORD_ARRAY = array( |
|
| 12 | - 'about', |
|
| 13 | - 'technologies', |
|
| 14 | - 'background', |
|
| 15 | - 'blog', |
|
| 16 | - 'Jacob Emerick'); |
|
| 17 | - |
|
| 18 | - protected function set_head_data() |
|
| 19 | - { |
|
| 20 | - $this->set_title(self::$TITLE); |
|
| 21 | - $this->set_description(self::$DESCRIPTION); |
|
| 22 | - $this->set_keywords(self::$KEYWORD_ARRAY); |
|
| 8 | + private static $TITLE = 'About the Blog | Jacob Emerick'; |
|
| 9 | + private static $DESCRIPTION = "A little bit about the awesomeness on Jacob Emerick's Blog, diving into the topics covered, technology used, and methodology of writing new posts."; |
|
| 10 | + |
|
| 11 | + private static $KEYWORD_ARRAY = array( |
|
| 12 | + 'about', |
|
| 13 | + 'technologies', |
|
| 14 | + 'background', |
|
| 15 | + 'blog', |
|
| 16 | + 'Jacob Emerick'); |
|
| 17 | + |
|
| 18 | + protected function set_head_data() |
|
| 19 | + { |
|
| 20 | + $this->set_title(self::$TITLE); |
|
| 21 | + $this->set_description(self::$DESCRIPTION); |
|
| 22 | + $this->set_keywords(self::$KEYWORD_ARRAY); |
|
| 23 | 23 | |
| 24 | - parent::set_head_data(); |
|
| 25 | - } |
|
| 24 | + parent::set_head_data(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - protected function set_body_data() |
|
| 28 | - { |
|
| 29 | - $this->set_body('view', 'About'); |
|
| 27 | + protected function set_body_data() |
|
| 28 | + { |
|
| 29 | + $this->set_body('view', 'About'); |
|
| 30 | 30 | |
| 31 | - parent::set_body_data(); |
|
| 32 | - } |
|
| 31 | + parent::set_body_data(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - protected function get_introduction() |
|
| 35 | - { |
|
| 34 | + protected function get_introduction() |
|
| 35 | + { |
|
| 36 | 36 | global $container; |
| 37 | 37 | $repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']); |
| 38 | 38 | $introduction_result = $repository->findByType('about'); |
| 39 | 39 | |
| 40 | - if($introduction_result !== null) |
|
| 41 | - { |
|
| 42 | - $introduction = array(); |
|
| 43 | - $introduction['title'] = $introduction_result['title']; |
|
| 44 | - $introduction['content'] = $introduction_result['content']; |
|
| 45 | - $introduction['image'] = $this->get_introduction_image($introduction_result['image']); |
|
| 40 | + if($introduction_result !== null) |
|
| 41 | + { |
|
| 42 | + $introduction = array(); |
|
| 43 | + $introduction['title'] = $introduction_result['title']; |
|
| 44 | + $introduction['content'] = $introduction_result['content']; |
|
| 45 | + $introduction['image'] = $this->get_introduction_image($introduction_result['image']); |
|
| 46 | 46 | |
| 47 | - return $introduction; |
|
| 48 | - } |
|
| 49 | - } |
|
| 47 | + return $introduction; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
@@ -5,115 +5,115 @@ |
||
| 5 | 5 | final class HomeController extends DefaultListController |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - private static $TITLE_MAIN = "Jacob Emerick's Blog | Posts on Hiking, Web Development, and more"; |
|
| 9 | - private static $TITLE_PAGINATED = "Page %d of %d in Jacob Emerick's Blog"; |
|
| 10 | - |
|
| 11 | - private static $DESCRIPTION_MAIN = "Jacob Emerick's Blog - a collection of posts about hiking the Upper Peninsula, learning to be a web developer, and other experiences of a young man."; |
|
| 12 | - private static $DESCRIPTION_PAGINATED = "Page %d of %d of posts about hiking in the Upper Peninsula, learning to be a web developer, and more on Jacob Emerick's Blog."; |
|
| 13 | - |
|
| 14 | - private static $KEYWORD_ARRAY = array( |
|
| 15 | - 'blog', |
|
| 16 | - 'Jacob Emerick', |
|
| 17 | - 'hiking', |
|
| 18 | - 'Huron Mountains', |
|
| 19 | - 'Peshekee Highlands', |
|
| 20 | - 'Keweenaw', |
|
| 21 | - 'Michigan', |
|
| 22 | - 'Upper Peninsula', |
|
| 23 | - 'leadership', |
|
| 24 | - 'web development', |
|
| 25 | - 'php programming', |
|
| 26 | - 'data handling', |
|
| 27 | - 'optimization'); |
|
| 28 | - |
|
| 29 | - private static $LIST_DESCRIPTION = 'Viewing %d - %d of %d total posts.'; |
|
| 30 | - |
|
| 31 | - protected function set_head_data() |
|
| 32 | - { |
|
| 33 | - parent::set_head_data(); |
|
| 8 | + private static $TITLE_MAIN = "Jacob Emerick's Blog | Posts on Hiking, Web Development, and more"; |
|
| 9 | + private static $TITLE_PAGINATED = "Page %d of %d in Jacob Emerick's Blog"; |
|
| 10 | + |
|
| 11 | + private static $DESCRIPTION_MAIN = "Jacob Emerick's Blog - a collection of posts about hiking the Upper Peninsula, learning to be a web developer, and other experiences of a young man."; |
|
| 12 | + private static $DESCRIPTION_PAGINATED = "Page %d of %d of posts about hiking in the Upper Peninsula, learning to be a web developer, and more on Jacob Emerick's Blog."; |
|
| 13 | + |
|
| 14 | + private static $KEYWORD_ARRAY = array( |
|
| 15 | + 'blog', |
|
| 16 | + 'Jacob Emerick', |
|
| 17 | + 'hiking', |
|
| 18 | + 'Huron Mountains', |
|
| 19 | + 'Peshekee Highlands', |
|
| 20 | + 'Keweenaw', |
|
| 21 | + 'Michigan', |
|
| 22 | + 'Upper Peninsula', |
|
| 23 | + 'leadership', |
|
| 24 | + 'web development', |
|
| 25 | + 'php programming', |
|
| 26 | + 'data handling', |
|
| 27 | + 'optimization'); |
|
| 28 | + |
|
| 29 | + private static $LIST_DESCRIPTION = 'Viewing %d - %d of %d total posts.'; |
|
| 30 | + |
|
| 31 | + protected function set_head_data() |
|
| 32 | + { |
|
| 33 | + parent::set_head_data(); |
|
| 34 | 34 | |
| 35 | - if($this->page == 1) |
|
| 36 | - $this->set_title(self::$TITLE_MAIN); |
|
| 37 | - else |
|
| 38 | - $this->set_title(sprintf(self::$TITLE_PAGINATED, $this->page, $this->total_pages)); |
|
| 35 | + if($this->page == 1) |
|
| 36 | + $this->set_title(self::$TITLE_MAIN); |
|
| 37 | + else |
|
| 38 | + $this->set_title(sprintf(self::$TITLE_PAGINATED, $this->page, $this->total_pages)); |
|
| 39 | 39 | |
| 40 | - if($this->page == 1) |
|
| 41 | - $this->set_description(self::$DESCRIPTION_MAIN); |
|
| 42 | - else |
|
| 43 | - $this->set_description(sprintf(self::$DESCRIPTION_PAGINATED, $this->page, $this->total_pages)); |
|
| 40 | + if($this->page == 1) |
|
| 41 | + $this->set_description(self::$DESCRIPTION_MAIN); |
|
| 42 | + else |
|
| 43 | + $this->set_description(sprintf(self::$DESCRIPTION_PAGINATED, $this->page, $this->total_pages)); |
|
| 44 | 44 | |
| 45 | - $this->set_keywords(self::$KEYWORD_ARRAY); |
|
| 46 | - } |
|
| 45 | + $this->set_keywords(self::$KEYWORD_ARRAY); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - protected function get_introduction() |
|
| 49 | - { |
|
| 50 | - if($this->page == 1) |
|
| 51 | - { |
|
| 48 | + protected function get_introduction() |
|
| 49 | + { |
|
| 50 | + if($this->page == 1) |
|
| 51 | + { |
|
| 52 | 52 | global $container; |
| 53 | 53 | $repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']); |
| 54 | 54 | $introduction_result = $repository->findByType('home'); |
| 55 | 55 | |
| 56 | - $introduction = array(); |
|
| 57 | - $introduction['title'] = $introduction_result['title']; |
|
| 58 | - $introduction['content'] = $introduction_result['content']; |
|
| 59 | - $introduction['image'] = $this->get_introduction_image($introduction_result['image']); |
|
| 56 | + $introduction = array(); |
|
| 57 | + $introduction['title'] = $introduction_result['title']; |
|
| 58 | + $introduction['content'] = $introduction_result['content']; |
|
| 59 | + $introduction['image'] = $this->get_introduction_image($introduction_result['image']); |
|
| 60 | 60 | |
| 61 | - return $introduction; |
|
| 62 | - } |
|
| 61 | + return $introduction; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return array( |
|
| 65 | - 'title' => "All of Jacob Emerick's posts, page {$this->page} of {$this->total_pages}."); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - protected function get_page_number() |
|
| 69 | - { |
|
| 70 | - $page = URLDecode::getPiece(1); |
|
| 71 | - if(isset($page) && is_numeric($page)) |
|
| 72 | - return $page; |
|
| 73 | - return 1; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - protected function get_list_results() |
|
| 77 | - { |
|
| 64 | + return array( |
|
| 65 | + 'title' => "All of Jacob Emerick's posts, page {$this->page} of {$this->total_pages}."); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + protected function get_page_number() |
|
| 69 | + { |
|
| 70 | + $page = URLDecode::getPiece(1); |
|
| 71 | + if(isset($page) && is_numeric($page)) |
|
| 72 | + return $page; |
|
| 73 | + return 1; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + protected function get_list_results() |
|
| 77 | + { |
|
| 78 | 78 | global $container; |
| 79 | 79 | $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
| 80 | 80 | return $repository->getActivePosts(self::$POSTS_PER_PAGE, $this->offset); |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - protected function get_list_description() |
|
| 84 | - { |
|
| 85 | - $start = $this->offset + 1; |
|
| 86 | - $end = min($this->offset + self::$POSTS_PER_PAGE, $this->get_total_post_count()); |
|
| 83 | + protected function get_list_description() |
|
| 84 | + { |
|
| 85 | + $start = $this->offset + 1; |
|
| 86 | + $end = min($this->offset + self::$POSTS_PER_PAGE, $this->get_total_post_count()); |
|
| 87 | 87 | |
| 88 | - return sprintf(self::$LIST_DESCRIPTION, $start, $end, $this->get_total_post_count()); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - protected function get_list_next_link() |
|
| 92 | - { |
|
| 93 | - if($this->page == 1) |
|
| 94 | - return; |
|
| 95 | - if($this->page == 2) |
|
| 96 | - return '/'; |
|
| 97 | - return '/' . ($this->page - 1) . '/'; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - protected function get_list_prev_link() |
|
| 101 | - { |
|
| 102 | - if(($this->page * self::$POSTS_PER_PAGE) >= $this->get_total_post_count()) |
|
| 103 | - return; |
|
| 104 | - return '/' . ($this->page + 1) . '/'; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - private $total_post_count; |
|
| 108 | - protected function get_total_post_count() |
|
| 109 | - { |
|
| 110 | - if(!isset($this->total_post_count)) { |
|
| 111 | - global $container; |
|
| 112 | - $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
| 113 | - $this->total_post_count = $repository->getActivePostsCount(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $this->total_post_count; |
|
| 117 | - } |
|
| 88 | + return sprintf(self::$LIST_DESCRIPTION, $start, $end, $this->get_total_post_count()); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + protected function get_list_next_link() |
|
| 92 | + { |
|
| 93 | + if($this->page == 1) |
|
| 94 | + return; |
|
| 95 | + if($this->page == 2) |
|
| 96 | + return '/'; |
|
| 97 | + return '/' . ($this->page - 1) . '/'; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + protected function get_list_prev_link() |
|
| 101 | + { |
|
| 102 | + if(($this->page * self::$POSTS_PER_PAGE) >= $this->get_total_post_count()) |
|
| 103 | + return; |
|
| 104 | + return '/' . ($this->page + 1) . '/'; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + private $total_post_count; |
|
| 108 | + protected function get_total_post_count() |
|
| 109 | + { |
|
| 110 | + if(!isset($this->total_post_count)) { |
|
| 111 | + global $container; |
|
| 112 | + $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
| 113 | + $this->total_post_count = $repository->getActivePostsCount(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $this->total_post_count; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |