public function protectFolder(Contao\DataContainer $dc)
	{
		$strPath = $dc->id;
		$rootDir = Contao\System::getContainer()->getParameter('kernel.project_dir');

		// Check if the folder has been renamed (see #6432, #934)
		if (Contao\Input::post('name'))
		{
			if (Contao\Validator::isInsecurePath(Contao\Input::post('name')))
			{
				throw new RuntimeException('Invalid file or folder name ' . Contao\Input::post('name'));
			}

			$count = 0;
			$strName = basename($strPath);

			if (($strNewPath = str_replace($strName, Contao\Input::post('name'), $strPath, $count)) && $count > 0 && is_dir($rootDir . '/' . $strNewPath))
			{
				$strPath = $strNewPath;
			}
		}

		// Only show for folders (see #5660)
		if (!is_dir($rootDir . '/' . $strPath))
		{
			return '';
		}

		$objFolder = new Contao\Folder($strPath);

		// Check if the folder or a parent folder is public
		$blnUnprotected = $objFolder->isUnprotected();

		// Disable the checkbox if a parent folder is public (see #712)
		$blnDisable = $blnUnprotected && !file_exists($rootDir . '/' . $strPath . '/.public');

		// Protect or unprotect the folder
		if (!$blnDisable && Contao\Input::post('FORM_SUBMIT') == 'tl_files')
		{
			if (Contao\Input::post($dc->inputName))
			{
				if (!$blnUnprotected)
				{
					$blnUnprotected = true;
					$objFolder->unprotect();

					$this->import('Contao\Automator', 'Automator');
					$this->Automator->generateSymlinks();
				}
			}
			else
			{
				if ($blnUnprotected)
				{
					$blnUnprotected = false;
					$objFolder->protect();

					$this->import('Contao\Automator', 'Automator');
					$this->Automator->generateSymlinks();
				}
			}
		}

		$class = $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['tl_class'] . ' cbx';

		if (Contao\Input::get('act') == 'editAll' || Contao\Input::get('act') == 'overrideAll')
		{
			$class = str_replace(array('w50', 'clr', 'wizard', 'long', 'm12', 'cbx'), '', $class);
		}

		$class = trim('widget ' . $class);

		return '
<div class="' . $class . '">
  <div id="ctrl_' . $dc->field . '" class="tl_checkbox_single_container">
    <input type="hidden" name="' . $dc->inputName . '" value=""><input type="checkbox" name="' . $dc->inputName . '" id="opt_' . $dc->inputName . '_0" class="tl_checkbox" value="1"' . (($blnUnprotected || basename($strPath) == '__new__') ? ' checked="checked"' : '') . ' onfocus="Backend.getScrollOffset()"' . ($blnDisable ? ' disabled' : '') . '> <label for="opt_' . $dc->inputName . '_0">' . $GLOBALS['TL_LANG']['tl_files']['protected'][0] . '</label>
  </div>' . (Contao\Config::get('showHelp') ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_files']['protected'][1] . '</p>' : '') . '
</div>';
	}
public function protectFolder(Contao\DataContainer $dc)
	{
		$strPath = $dc->id;
		$rootDir = Contao\System::getContainer()->getParameter('kernel.project_dir');

		
		if (Contao\Input::post('name'))
		{
			if (Contao\Validator::isInsecurePath(Contao\Input::post('name')))
			{
				throw new RuntimeException('Invalid file or folder name ' . Contao\Input::post('name'));
			}

			$count = 0;
			$strName = basename($strPath);

			if (($strNewPath = str_replace($strName, Contao\Input::post('name'), $strPath, $count)) && $count > 0 && is_dir($rootDir . '/' . $strNewPath))
			{
				$strPath = $strNewPath;
			}
		}

		
		if (!is_dir($rootDir . '/' . $strPath))
		{
			return '';
		}

		$objFolder = new Contao\Folder($strPath);

		
		$blnUnprotected = $objFolder->isUnprotected();

		
		$blnDisable = $blnUnprotected && !file_exists($rootDir . '/' . $strPath . '/.public');

		
		if (!$blnDisable && Contao\Input::post('FORM_SUBMIT') == 'tl_files')
		{
			if (Contao\Input::post($dc->inputName))
			{
				if (!$blnUnprotected)
				{
					$blnUnprotected = true;
					$objFolder->unprotect();

					$this->import('Contao\Automator', 'Automator');
					$this->Automator->generateSymlinks();
				}
			}
			else
			{
				if ($blnUnprotected)
				{
					$blnUnprotected = false;
					$objFolder->protect();

					$this->import('Contao\Automator', 'Automator');
					$this->Automator->generateSymlinks();
				}
			}
		}

		$class = $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['tl_class'] . ' cbx';

		if (Contao\Input::get('act') == 'editAll' || Contao\Input::get('act') == 'overrideAll')
		{
			$class = str_replace(array('w50', 'clr', 'wizard', 'long', 'm12', 'cbx'), '', $class);
		}

		$class = trim('widget ' . $class);

		return '
<div class="' . $class . '">
  <div id="ctrl_' . $dc->field . '" class="tl_checkbox_single_container">
    <input type="hidden" name="' . $dc->inputName . '" value=""><input type="checkbox" name="' . $dc->inputName . '" id="opt_' . $dc->inputName . '_0" class="tl_checkbox" value="1"' . (($blnUnprotected || basename($strPath) == '__new__') ? ' checked="checked"' : '') . ' onfocus="Backend.getScrollOffset()"' . ($blnDisable ? ' disabled' : '') . '> <label for="opt_' . $dc->inputName . '_0">' . $GLOBALS['TL_LANG']['tl_files']['protected'][0] . '</label>
  </div>' . (Contao\Config::get('showHelp') ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_files']['protected'][1] . '</p>' : '') . '
</div>';
	}
public function protectFolder ( Contao \ DataContainer $ dc ) { $ strPath = $ dc -> id ; $ rootDir = Contao \ System :: getContainer ( ) -> getParameter ( 'kernel.project_dir' ) ; // Check if the folder has been renamed (see #6432, #934) if ( Contao \ Input :: post ( 'name' ) ) { if ( Contao \ Validator :: isInsecurePath ( Contao \ Input :: post ( 'name' ) ) ) { throw new RuntimeException ( 'Invalid file or folder name ' . Contao \ Input :: post ( 'name' ) ) ; } $ count = 0 ; $ strName = basename ( $ strPath ) ; if ( ( $ strNewPath = str_replace ( $ strName , Contao \ Input :: post ( 'name' ) , $ strPath , $ count ) ) && $ count > 0 && is_dir ( $ rootDir . '/' . $ strNewPath ) ) { $ strPath = $ strNewPath ; } } // Only show for folders (see #5660) if ( ! is_dir ( $ rootDir . '/' . $ strPath ) ) { return '' ; } $ objFolder = new Contao \ Folder ( $ strPath ) ; // Check if the folder or a parent folder is public $ blnUnprotected = $ objFolder -> isUnprotected ( ) ; // Disable the checkbox if a parent folder is public (see #712) $ blnDisable = $ blnUnprotected && ! file_exists ( $ rootDir . '/' . $ strPath . '/.public' ) ; // Protect or unprotect the folder if ( ! $ blnDisable && Contao \ Input :: post ( 'FORM_SUBMIT' ) == 'tl_files' ) { if ( Contao \ Input :: post ( $ dc -> inputName ) ) { if ( ! $ blnUnprotected ) { $ blnUnprotected = true ; $ objFolder -> unprotect ( ) ; $ this -> import ( 'Contao\Automator' , 'Automator' ) ; $ this -> Automator -> generateSymlinks ( ) ; } } else { if ( $ blnUnprotected ) { $ blnUnprotected = false ; $ objFolder -> protect ( ) ; $ this -> import ( 'Contao\Automator' , 'Automator' ) ; $ this -> Automator -> generateSymlinks ( ) ; } } } $ class = $ GLOBALS [ 'TL_DCA' ] [ $ dc -> table ] [ 'fields' ] [ $ dc -> field ] [ 'eval' ] [ 'tl_class' ] . ' cbx' ; if ( Contao \ Input :: get ( 'act' ) == 'editAll' || Contao \ Input :: get ( 'act' ) == 'overrideAll' ) { $ class = str_replace ( array ( 'w50' , 'clr' , 'wizard' , 'long' , 'm12' , 'cbx' ) , '' , $ class ) ; } $ class = trim ( 'widget ' . $ class ) ; return '
<div class="' . $ class . '">
  <div id="ctrl_' . $ dc -> field . '" class="tl_checkbox_single_container">
    <input type="hidden" name="' . $ dc -> inputName . '" value=""><input type="checkbox" name="' . $ dc -> inputName . '" id="opt_' . $ dc -> inputName . '_0" class="tl_checkbox" value="1"' . ( ( $ blnUnprotected || basename ( $ strPath ) == '__new__' ) ? ' checked="checked"' : '' ) . ' onfocus="Backend.getScrollOffset()"' . ( $ blnDisable ? ' disabled' : '' ) . '> <label for="opt_' . $ dc -> inputName . '_0">' . $ GLOBALS [ 'TL_LANG' ] [ 'tl_files' ] [ 'protected' ] [ 0 ] . '</label>
  </div>' . ( Contao \ Config :: get ( 'showHelp' ) ? '
  <p class="tl_help tl_tip">' . $ GLOBALS [ 'TL_LANG' ] [ 'tl_files' ] [ 'protected' ] [ 1 ] . '</p>' : '' ) . '
</div>' ; }
Return a checkbox to protect a folder

@param Contao\DataContainer $dc

@return string

@throws RuntimeException
Return a checkbox to protect a folder