core-bundle/src/Resources/contao/elements/ContentDownload.php
protected function compile()
	{
		$objFile = new File($this->singleSRC);

		if (TL_MODE == 'FE')
		{
			global $objPage;

			$arrMeta = Frontend::getMetaData($this->objFile->meta, $objPage->language);

			if (empty($arrMeta) && $objPage->rootFallbackLanguage !== null)
			{
				$arrMeta = Frontend::getMetaData($this->objFile->meta, $objPage->rootFallbackLanguage);
			}
		}
		else
		{
			$arrMeta = Frontend::getMetaData($this->objFile->meta, $GLOBALS['TL_LANGUAGE']);
		}

		// Use the meta title (see #1459)
		if (!$this->overwriteLink && isset($arrMeta['title']))
		{
			$this->linkTitle = StringUtil::specialchars($arrMeta['title']);
		}

		if (!$this->titleText || !$this->overwriteLink)
		{
			$this->titleText = sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename);
		}

		$strHref = Environment::get('request');

		// Remove an existing file parameter (see #5683)
		if (isset($_GET['file']))
		{
			$strHref = preg_replace('/(&(amp;)?|\?)file=[^&]+/', '', $strHref);
		}

		if (isset($_GET['cid']))
		{
			$strHref = preg_replace('/(&(amp;)?|\?)cid=\d+/', '', $strHref);
		}

		$strHref .= (strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . System::urlEncode($objFile->value) . '&amp;cid=' . $this->id;

		$this->Template->link = $this->linkTitle ?: $objFile->basename;
		$this->Template->title = StringUtil::specialchars($this->titleText);
		$this->Template->href = $strHref;
		$this->Template->filesize = $this->getReadableSize($objFile->filesize, 1);
		$this->Template->icon = Image::getPath($objFile->icon);
		$this->Template->mime = $objFile->mime;
		$this->Template->extension = $objFile->extension;
		$this->Template->path = $objFile->dirname;
	}
protected function compile()
	{
		$objFile = new File($this->singleSRC);

		if (TL_MODE == 'FE')
		{
			global $objPage;

			$arrMeta = Frontend::getMetaData($this->objFile->meta, $objPage->language);

			if (empty($arrMeta) && $objPage->rootFallbackLanguage !== null)
			{
				$arrMeta = Frontend::getMetaData($this->objFile->meta, $objPage->rootFallbackLanguage);
			}
		}
		else
		{
			$arrMeta = Frontend::getMetaData($this->objFile->meta, $GLOBALS['TL_LANGUAGE']);
		}

		// Use the meta title (see #1459)
		if (!$this->overwriteLink && isset($arrMeta['title']))
		{
			$this->linkTitle = StringUtil::specialchars($arrMeta['title']);
		}

		if (!$this->titleText || !$this->overwriteLink)
		{
			$this->titleText = sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename);
		}

		$strHref = Environment::get('request');

		// Remove an existing file parameter (see #5683)
		if (isset($_GET['file']))
		{
			$strHref = preg_replace('/(&(amp;)?|\?)file=[^&]+/', '', $strHref);
		}

		if (isset($_GET['cid']))
		{
			$strHref = preg_replace('/(&(amp;)?|\?)cid=\d+/', '', $strHref);
		}

		$strHref .= (strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . System::urlEncode($objFile->value) . '&amp;cid=' . $this->id;

		$this->Template->link = $this->linkTitle ?: $objFile->basename;
		$this->Template->title = StringUtil::specialchars($this->titleText);
		$this->Template->href = $strHref;
		$this->Template->filesize = $this->getReadableSize($objFile->filesize, 1);
		$this->Template->icon = Image::getPath($objFile->icon);
		$this->Template->mime = $objFile->mime;
		$this->Template->extension = $objFile->extension;
		$this->Template->path = $objFile->dirname;
	}
protected function compile ( ) { $ objFile = new File ( $ this -> singleSRC ) ; if ( TL_MODE == 'FE' ) { global $ objPage ; $ arrMeta = Frontend :: getMetaData ( $ this -> objFile -> meta , $ objPage -> language ) ; if ( empty ( $ arrMeta ) && $ objPage -> rootFallbackLanguage !== null ) { $ arrMeta = Frontend :: getMetaData ( $ this -> objFile -> meta , $ objPage -> rootFallbackLanguage ) ; } } else { $ arrMeta = Frontend :: getMetaData ( $ this -> objFile -> meta , $ GLOBALS [ 'TL_LANGUAGE' ] ) ; } // Use the meta title (see #1459) if ( ! $ this -> overwriteLink && isset ( $ arrMeta [ 'title' ] ) ) { $ this -> linkTitle = StringUtil :: specialchars ( $ arrMeta [ 'title' ] ) ; } if ( ! $ this -> titleText || ! $ this -> overwriteLink ) { $ this -> titleText = sprintf ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'download' ] , $ objFile -> basename ) ; } $ strHref = Environment :: get ( 'request' ) ; // Remove an existing file parameter (see #5683) if ( isset ( $ _GET [ 'file' ] ) ) { $ strHref = preg_replace ( '/(&(amp;)?|\?)file=[^&]+/' , '' , $ strHref ) ; } if ( isset ( $ _GET [ 'cid' ] ) ) { $ strHref = preg_replace ( '/(&(amp;)?|\?)cid=\d+/' , '' , $ strHref ) ; } $ strHref .= ( strpos ( $ strHref , '?' ) !== false ? '&amp;' : '?' ) . 'file=' . System :: urlEncode ( $ objFile -> value ) . '&amp;cid=' . $ this -> id ; $ this -> Template -> link = $ this -> linkTitle ? : $ objFile -> basename ; $ this -> Template -> title = StringUtil :: specialchars ( $ this -> titleText ) ; $ this -> Template -> href = $ strHref ; $ this -> Template -> filesize = $ this -> getReadableSize ( $ objFile -> filesize , 1 ) ; $ this -> Template -> icon = Image :: getPath ( $ objFile -> icon ) ; $ this -> Template -> mime = $ objFile -> mime ; $ this -> Template -> extension = $ objFile -> extension ; $ this -> Template -> path = $ objFile -> dirname ; }
Generate the content element
Generate the content element