Esempio n. 1
0
	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;
	}
	public function __construct()
	{
		parent::__construct();
		
        global $container;
        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
        $this->post = $repository->findPostByPath(URLDecode::getPiece(2));

		if($this->post == null)
			$this->eject();
		
		$this->handle_comment_submit(
			self::$BLOG_SITE_ID,
			$this->post['path'],
			Loader::getRootUrl('blog') . $this->post['category'] . '/' . $this->post['path'] . '/',
			$this->post['title']);

        global $container;
        $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
        $this->tags = $repository->getTagsForPost($this->post['id']);
	}
	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);
	}