protected function check_for_special_redirect($uri) { if(preg_match('@^/post_([0-9]{4}-[0-9]{2}-[0-9]{2})_([a-z0-9-]+)(/?)$@', $uri, $matches)) { global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $post = $repository->findPostByPath($matches[2]); if(!$post) { Loader::loadNew('controller', '/Error404Controller') ->activate(); } Loader::load('utility', 'Content'); $uri = Content::instance('URLSafe', "/{$post['category']}/{$post['path']}/")->activate(); } else { $post_uri = URLDecode::getPiece(1); if($post_uri !== null) { global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $post = $repository->findPostByPath($post_uri); if($post != false) { Loader::load('utility', 'Content'); $uri = Content::instance('URLSafe', "/{$post['category']}/{$post['path']}/")->activate(); } } } if($uri == '/search/') { if(Request::getGet('submit') == 'Submit Search' && Request::getGet('search')) { $uri .= Request::getGet('search'); $uri .= '/'; } } return $uri; }
protected function get_total_post_count() { if(!isset($this->total_post_count)) { global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $this->total_post_count = $repository->getActivePostsCountByTag($this->tag['id']); } return $this->total_post_count; }
private function get_related_posts() { $tag_array = array(); foreach($this->tags as $tag) { $tag_array[] = $tag['id']; } $series_posts = $this->fetch_series_posts(); $exclude_post_array = array(); foreach($series_posts as $series_post) { $exclude_post_array[] = $series_post['post']; } global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $post_result = $repository->getActivePostsByRelatedTags($this->post['id']); $post_array = array(); foreach($post_result as $post_row) { $post = new stdclass(); $post->title = $post_row['title']; $post->url = Loader::getRootUrl('blog') . "{$post_row['category']}/{$post_row['path']}/"; $post->category = ucwords(str_replace('-', ' ', $post_row['category'])); $post->thumb = Content::instance('FetchFirstPhoto', $post_row['body'])->activate(); $post->body = Content::instance('SmartTrim', $post_row['body'])->activate(($post->thumb !== '') ? self::$POST_LENGTH_SHORT : self::$POST_LENGTH_LONG); $post_array[] = $post; } return $post_array; }
private function get_search_result() { if(!isset($this->search_result)) { global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $posts = $repository->getActivePosts(); $this->search_result = Search::instance() ->setQuery($this->query) ->setResult($posts) ->setWeight(self::$SEARCH_WEIGHTS) ->perform(); } return $this->search_result; }
private function get_link($string, $is_absolute, $anchor = '') { list($type, $uri) = explode('/', $string, 2); $link = ''; switch($type) { case 'blog' : global $container; $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); $post = $repository->findPostByPath($uri); if($post === NULL) return; $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; $link .= "{$post['category']}/{$post['path']}/"; if($anchor == '') $anchor = $post['title']; break; case 'blog-tag' : $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; $link .= "tag/{$uri}/"; if($anchor == '') { $anchor = $uri; $anchor = str_replace('-', ' ', $anchor); $anchor = ucwords($anchor); } break; case 'journal' : Loader::load('collector', 'waterfall/LogCollector'); $log = LogCollector::getByAlias($uri); if($log === NULL) return; $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; $link .= "journal/{$log->alias}/"; if($anchor == '') $anchor = $log->title; break; case 'falls' : $pieces = explode('/', $uri); if (count($pieces) == 1) { Loader::load('collector', 'waterfall/WatercourseCollector'); list ($watercourse_alias) = $pieces; $watercourse = WatercourseCollector::getByAlias($watercourse_alias); if ($watercourse == null) { return; } $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; $link .= "{$watercourse->alias}/"; if ($anchor == '') { $anchor = $watercourse->name; } } else if (count($pieces) == 2) { Loader::load('collector', 'waterfall/WaterfallCollector'); list ($watercourse_alias, $waterfall_alias) = $pieces; $waterfall = WaterfallCollector::getByAlias($watercourse_alias, $waterfall_alias); if ($waterfall == null) { return; } $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; $link .= "{$waterfall->watercourse_alias}/{$waterfall->alias}/"; if ($anchor == '') { $anchor = $waterfall->name; } } break; default : break; } return sprintf(self::$LINK_CONTENT, $link, $anchor); }