news-bundle/src/Resources/contao/classes/News.php
public static function generateNewsUrl($objItem, $blnAddArchive=false, $blnAbsolute=false)
	{
		$strCacheKey = 'id_' . $objItem->id . ($blnAbsolute ? '_absolute' : '');

		// Load the URL from cache
		if (isset(self::$arrUrlCache[$strCacheKey]))
		{
			return self::$arrUrlCache[$strCacheKey];
		}

		// Initialize the cache
		self::$arrUrlCache[$strCacheKey] = null;

		switch ($objItem->source)
		{
			// Link to an external page
			case 'external':
				if (substr($objItem->url, 0, 7) == 'mailto:')
				{
					self::$arrUrlCache[$strCacheKey] = StringUtil::encodeEmail($objItem->url);
				}
				else
				{
					self::$arrUrlCache[$strCacheKey] = ampersand($objItem->url);
				}
				break;

			// Link to an internal page
			case 'internal':
				if (($objTarget = $objItem->getRelated('jumpTo')) instanceof PageModel)
				{
					/** @var PageModel $objTarget */
					self::$arrUrlCache[$strCacheKey] = ampersand($blnAbsolute ? $objTarget->getAbsoluteUrl() : $objTarget->getFrontendUrl());
				}
				break;

			// Link to an article
			case 'article':
				if (($objArticle = ArticleModel::findByPk($objItem->articleId)) instanceof ArticleModel && ($objPid = $objArticle->getRelated('pid')) instanceof PageModel)
				{
					$params = '/articles/' . ($objArticle->alias ?: $objArticle->id);

					/** @var PageModel $objPid */
					self::$arrUrlCache[$strCacheKey] = ampersand($blnAbsolute ? $objPid->getAbsoluteUrl($params) : $objPid->getFrontendUrl($params));
				}
				break;
		}

		// Link to the default page
		if (self::$arrUrlCache[$strCacheKey] === null)
		{
			$objPage = PageModel::findByPk($objItem->getRelated('pid')->jumpTo);

			if (!$objPage instanceof PageModel)
			{
				self::$arrUrlCache[$strCacheKey] = ampersand(Environment::get('request'), true);
			}
			else
			{
				$params = (Config::get('useAutoItem') ? '/' : '/items/') . ($objItem->alias ?: $objItem->id);

				self::$arrUrlCache[$strCacheKey] = ampersand($blnAbsolute ? $objPage->getAbsoluteUrl($params) : $objPage->getFrontendUrl($params));
			}

			// Add the current archive parameter (news archive)
			if ($blnAddArchive && Input::get('month') != '')
			{
				self::$arrUrlCache[$strCacheKey] .= '?month=' . Input::get('month');
			}
		}

		return self::$arrUrlCache[$strCacheKey];
	}
public static function generateNewsUrl($objItem, $blnAddArchive=false, $blnAbsolute=false)
	{
		$strCacheKey = 'id_' . $objItem->id . ($blnAbsolute ? '_absolute' : '');

		// Load the URL from cache
		if (isset(self::$arrUrlCache[$strCacheKey]))
		{
			return self::$arrUrlCache[$strCacheKey];
		}

		// Initialize the cache
		self::$arrUrlCache[$strCacheKey] = null;

		switch ($objItem->source)
		{
			// Link to an external page
			case 'external':
				if (substr($objItem->url, 0, 7) == 'mailto:')
				{
					self::$arrUrlCache[$strCacheKey] = StringUtil::encodeEmail($objItem->url);
				}
				else
				{
					self::$arrUrlCache[$strCacheKey] = ampersand($objItem->url);
				}
				break;

			// Link to an internal page
			case 'internal':
				if (($objTarget = $objItem->getRelated('jumpTo')) instanceof PageModel)
				{
					/** @var PageModel $objTarget */
					self::$arrUrlCache[$strCacheKey] = ampersand($blnAbsolute ? $objTarget->getAbsoluteUrl() : $objTarget->getFrontendUrl());
				}
				break;

			// Link to an article
			case 'article':
				if (($objArticle = ArticleModel::findByPk($objItem->articleId)) instanceof ArticleModel && ($objPid = $objArticle->getRelated('pid')) instanceof PageModel)
				{
					$params = '/articles/' . ($objArticle->alias ?: $objArticle->id);

					/** @var PageModel $objPid */
					self::$arrUrlCache[$strCacheKey] = ampersand($blnAbsolute ? $objPid->getAbsoluteUrl($params) : $objPid->getFrontendUrl($params));
				}
				break;
		}

		// Link to the default page
		if (self::$arrUrlCache[$strCacheKey] === null)
		{
			$objPage = PageModel::findByPk($objItem->getRelated('pid')->jumpTo);

			if (!$objPage instanceof PageModel)
			{
				self::$arrUrlCache[$strCacheKey] = ampersand(Environment::get('request'), true);
			}
			else
			{
				$params = (Config::get('useAutoItem') ? '/' : '/items/') . ($objItem->alias ?: $objItem->id);

				self::$arrUrlCache[$strCacheKey] = ampersand($blnAbsolute ? $objPage->getAbsoluteUrl($params) : $objPage->getFrontendUrl($params));
			}

			// Add the current archive parameter (news archive)
			if ($blnAddArchive && Input::get('month') != '')
			{
				self::$arrUrlCache[$strCacheKey] .= '?month=' . Input::get('month');
			}
		}

		return self::$arrUrlCache[$strCacheKey];
	}
public static function generateNewsUrl ( $ objItem , $ blnAddArchive = false , $ blnAbsolute = false ) { $ strCacheKey = 'id_' . $ objItem -> id . ( $ blnAbsolute ? '_absolute' : '' ) ; // Load the URL from cache if ( isset ( self :: $ arrUrlCache [ $ strCacheKey ] ) ) { return self :: $ arrUrlCache [ $ strCacheKey ] ; } // Initialize the cache self :: $ arrUrlCache [ $ strCacheKey ] = null ; switch ( $ objItem -> source ) { // Link to an external page case 'external' : if ( substr ( $ objItem -> url , 0 , 7 ) == 'mailto:' ) { self :: $ arrUrlCache [ $ strCacheKey ] = StringUtil :: encodeEmail ( $ objItem -> url ) ; } else { self :: $ arrUrlCache [ $ strCacheKey ] = ampersand ( $ objItem -> url ) ; } break ; // Link to an internal page case 'internal' : if ( ( $ objTarget = $ objItem -> getRelated ( 'jumpTo' ) ) instanceof PageModel ) { /** @var PageModel $objTarget */ self :: $ arrUrlCache [ $ strCacheKey ] = ampersand ( $ blnAbsolute ? $ objTarget -> getAbsoluteUrl ( ) : $ objTarget -> getFrontendUrl ( ) ) ; } break ; // Link to an article case 'article' : if ( ( $ objArticle = ArticleModel :: findByPk ( $ objItem -> articleId ) ) instanceof ArticleModel && ( $ objPid = $ objArticle -> getRelated ( 'pid' ) ) instanceof PageModel ) { $ params = '/articles/' . ( $ objArticle -> alias ? : $ objArticle -> id ) ; /** @var PageModel $objPid */ self :: $ arrUrlCache [ $ strCacheKey ] = ampersand ( $ blnAbsolute ? $ objPid -> getAbsoluteUrl ( $ params ) : $ objPid -> getFrontendUrl ( $ params ) ) ; } break ; } // Link to the default page if ( self :: $ arrUrlCache [ $ strCacheKey ] === null ) { $ objPage = PageModel :: findByPk ( $ objItem -> getRelated ( 'pid' ) -> jumpTo ) ; if ( ! $ objPage instanceof PageModel ) { self :: $ arrUrlCache [ $ strCacheKey ] = ampersand ( Environment :: get ( 'request' ) , true ) ; } else { $ params = ( Config :: get ( 'useAutoItem' ) ? '/' : '/items/' ) . ( $ objItem -> alias ? : $ objItem -> id ) ; self :: $ arrUrlCache [ $ strCacheKey ] = ampersand ( $ blnAbsolute ? $ objPage -> getAbsoluteUrl ( $ params ) : $ objPage -> getFrontendUrl ( $ params ) ) ; } // Add the current archive parameter (news archive) if ( $ blnAddArchive && Input :: get ( 'month' ) != '' ) { self :: $ arrUrlCache [ $ strCacheKey ] .= '?month=' . Input :: get ( 'month' ) ; } } return self :: $ arrUrlCache [ $ strCacheKey ] ; }
Generate a URL and return it as string

@param NewsModel $objItem
@param boolean   $blnAddArchive
@param boolean   $blnAbsolute

@return string
Generate a URL and return it as string