本文整理汇总了PHP中TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr方法的典型用法代码示例。如果您正苦于以下问题:PHP GeneralUtility::validPathStr方法的具体用法?PHP GeneralUtility::validPathStr怎么用?PHP GeneralUtility::validPathStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Utility\GeneralUtility
的用法示例。
在下文中一共展示了GeneralUtility::validPathStr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
/**
* Unset all additional properties of test classes to help PHP
* garbage collection. This reduces memory footprint with lots
* of tests.
*
* If owerwriting tearDown() in test classes, please call
* parent::tearDown() at the end. Unsetting of own properties
* is not needed this way.
*
* @throws \RuntimeException
* @return void
*/
protected function tearDown()
{
// Unset properties of test classes to safe memory
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
$declaringClass = $property->getDeclaringClass()->getName();
if (!$property->isStatic() && $declaringClass !== \TYPO3\CMS\Core\Tests\UnitTestCase::class && $declaringClass !== \TYPO3\CMS\Core\Tests\BaseTestCase::class && strpos($property->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) {
$propertyName = $property->getName();
unset($this->{$propertyName});
}
}
unset($reflection);
// Delete registered test files and directories
foreach ($this->testFilesToDelete as $absoluteFileName) {
$absoluteFileName = GeneralUtility::fixWindowsFilePath(PathUtility::getCanonicalPath($absoluteFileName));
if (!GeneralUtility::validPathStr($absoluteFileName)) {
throw new \RuntimeException('tearDown() cleanup: Filename contains illegal characters', 1410633087);
}
if (!StringUtility::beginsWith($absoluteFileName, PATH_site . 'typo3temp/')) {
throw new \RuntimeException('tearDown() cleanup: Files to delete must be within typo3temp/', 1410633412);
}
// file_exists returns false for links pointing to not existing targets, so handle links before next check.
if (@is_link($absoluteFileName) || @is_file($absoluteFileName)) {
unlink($absoluteFileName);
} elseif (@is_dir($absoluteFileName)) {
GeneralUtility::rmdir($absoluteFileName, true);
} else {
throw new \RuntimeException('tearDown() cleanup: File, link or directory does not exist', 1410633510);
}
}
$this->testFilesToDelete = array();
}
示例2: checkExtension
/**
* Check extension of given filename
*
* @param string $filename Filename like (upload.png)
* @return bool If Extension is allowed
*/
public static function checkExtension($filename)
{
$extensionList = 'jpg,jpeg,png,gif,bmp';
$settings = self::getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_femanager.']['settings.'];
if (!empty($settings['misc.']['uploadFileExtension'])) {
$extensionList = $settings['misc.']['uploadFileExtension'];
$extensionList = str_replace(' ', '', $extensionList);
}
$fileInfo = pathinfo($filename);
return !empty($fileInfo['extension']) && GeneralUtility::inList($extensionList, strtolower($fileInfo['extension'])) && GeneralUtility::verifyFilenameAgainstDenyPattern($filename) && GeneralUtility::validPathStr($filename);
}
示例3: validateAdditionalFields
/**
* Validates the additional fields' values
*
* @param array $submittedData An array containing the data submitted by the add/edit task form
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
* @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
{
$validInput = true;
$directoriesToClean = GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'DirectoriesToClean'], true);
foreach ($directoriesToClean as $path) {
$path = trim($path, DIRECTORY_SEPARATOR);
if (!(strlen($path) > 0 && file_exists(PATH_site . $path) && GeneralUtility::isAllowedAbsPath(PATH_site . $path) && GeneralUtility::validPathStr($path) && !GeneralUtility::inList($this->blackList, $path))) {
$validInput = false;
break;
}
}
if (empty($submittedData[$this->fieldPrefix . 'DirectoriesToClean']) || $validInput === false) {
$schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:minicleaner/locallang.xml:error.pathNotValid'), FlashMessage::ERROR);
$validInput = false;
}
return $validInput;
}
示例4: execute
public function execute()
{
$directories = GeneralUtility::trimExplode(LF, $this->directoriesToClean, true);
if (is_array($directories)) {
foreach ($directories as $key => $directory) {
$path = PATH_site . trim($directory, DIRECTORY_SEPARATOR);
if ($path != PATH_site && file_exists($path) && GeneralUtility::isAllowedAbsPath($path) && GeneralUtility::validPathStr($path) && !GeneralUtility::inList($this->blackList, $path)) {
$result = GeneralUtility::flushDirectory($path, true);
if ($result === false) {
GeneralUtility::devLog($GLOBALS['LANG']->sL('LLL:EXT:minicleaner/locallang.xml:error.couldNotFlushDirectory'), 'minicleaner', 3);
return false;
}
} else {
GeneralUtility::devLog($GLOBALS['LANG']->sL('LLL:EXT:minicleaner/locallang.xml:error.pathNotFound'), 'minicleaner', 3);
return false;
}
}
}
return true;
}
示例5: checkPathAgainstMounts
/**
* Checks if $thePath is a path under one of the paths in $this->mounts
* See comment in the header of this class.
*
* @param string $thePath MUST HAVE a trailing '/' in order to match correctly with the mounts
* @return string The key to the first mount found, otherwise nothing is returned.
* @see init()
* @todo: deprecate this function, now done in the Storage object. But still in use by impexp and ExtendedFileUtility
* @deprecated but still in use in the Core. Don't use in your extensions!
*/
public function checkPathAgainstMounts($thePath)
{
if ($thePath && GeneralUtility::validPathStr($thePath) && is_array($this->mounts)) {
foreach ($this->mounts as $k => $val) {
if (GeneralUtility::isFirstPartOfStr($thePath, $val['path'])) {
return $k;
}
}
}
}
示例6: getUploadedFileInfo
/**
* Get file info of uploaded file
*
* @return array
*/
protected function getUploadedFileInfo()
{
$uploadData = $_FILES[$this->getNamespace()];
$fileData = [];
if (is_array($uploadData) && count($uploadData) > 0) {
$filename = str_replace(chr(0), '', $uploadData['name'][$this->fieldname]);
$type = $uploadData['type'][$this->fieldname];
$tmpName = $uploadData['tmp_name'][$this->fieldname];
$error = $uploadData['error'][$this->fieldname];
$size = $uploadData['size'][$this->fieldname];
if ($filename !== null && $filename !== '' && GeneralUtility::validPathStr($filename)) {
if ($this->settings['useEncryptedFilename']) {
$filenameParts = GeneralUtility::trimExplode('.', $filename);
$extension = array_pop($filenameParts);
$filename = md5(mktime() . mt_rand() . $filename . $tmpName . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . '.' . $extension;
}
$fileData = array('filename' => $filename, 'type' => $type, 'tmp_name' => $tmpName, 'error' => $error, 'size' => $size);
}
}
return $fileData;
}
示例7: isPathValid
/**
* Wrapper for \TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr()
*
* @param string $theFile Filepath to evaluate
* @return bool TRUE if no '/', '..' or '\' is in the $theFile
* @see \TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr()
*/
protected function isPathValid($theFile)
{
return GeneralUtility::validPathStr($theFile);
}
示例8: clean_directory
/**
* Cleans $theDir for slashes in the end of the string and returns the new path, if it exists on the server.
*
* @param string $theDir Absolute path to directory
* @return string The directory path if it existed as was valid to access.
* @access private
* @see filelist()
*/
public function clean_directory($theDir)
{
// proceeds if no '//', '..' or '\' is in the $theFile
if (GeneralUtility::validPathStr($theDir)) {
// Removes all dots, slashes and spaces after a path...
$theDir = preg_replace('/[\\/\\. ]*$/', '', $theDir);
if (!GeneralUtility::isAbsPath($theDir) && @is_dir($theDir)) {
return $theDir;
}
}
return '';
}
示例9: isDir
/**
* Test if a value is a valid and existing directory
*
* @param string value
* @param array (optional) additional info, will be displayed as debug message, if a key "message" exists this will be appended to the error message
* @throws Tx_PtExtbase_Exception_Assertion if assertion fails
*/
public static function isDir($val, array $info = array())
{
self::isNotEmptyString($val, $info);
$filePath = GeneralUtility::getFileAbsFileName($val, false);
return self::test(GeneralUtility::validPathStr($filePath) && is_dir($filePath), true, $info);
}
示例10: evalWriteFile
/**
* Evaluate the environment for editing a staticFileEdit file.
* Called for almost all fields being saved in the database. Is called without
* an instance of \TYPO3\CMS\Core\Html\RteHtmlParser::evalWriteFile()
*
* @param array $pArr Parameters for the current field as found in types-config
* @param array $currentRecord Current record we are editing.
* @return mixed On success an array with various information is returned, otherwise a string with an error message
*/
public static function evalWriteFile($pArr, $currentRecord)
{
// Write file configuration:
if (is_array($pArr)) {
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'] && substr($GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'], -1) == '/' && @is_dir(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'])) {
$SW_p = $pArr['parameters'];
$SW_editFileField = trim($SW_p[0]);
$SW_editFile = $currentRecord[$SW_editFileField];
if ($SW_editFileField && $SW_editFile && GeneralUtility::validPathStr($SW_editFile)) {
$SW_relpath = $GLOBALS['TYPO3_CONF_VARS']['BE']['staticFileEditPath'] . $SW_editFile;
$SW_editFile = PATH_site . $SW_relpath;
if (@is_file($SW_editFile)) {
return array('editFile' => $SW_editFile, 'relEditFile' => $SW_relpath, 'contentField' => trim($SW_p[1]), 'markerField' => trim($SW_p[2]), 'loadFromFileField' => trim($SW_p[3]), 'statusField' => trim($SW_p[4]));
} else {
return 'ERROR: Editfile \'' . $SW_relpath . '\' did not exist';
}
} else {
return 'ERROR: Edit file name could not be found or was bad.';
}
} else {
return 'ERROR: staticFileEditPath was not set, not set correctly or did not exist!';
}
}
}
示例11: isPathValid
/**
* Wrapper for t3lib_div::validPathStr()
*
* @param string Filepath to evaluate
* @return boolean TRUE, if no '//', '..' or '\' is in the $theFile
* @see t3lib_div::validPathStr()
* @todo Define visibility
*/
public function isPathValid($theFile)
{
// @todo: should go into the LocalDriver in a protected way (not important to the outside world)
return \TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr($theFile);
}
示例12: addFileMount
/**
* Adds a filemount to the users array of filemounts, $this->groupData['filemounts'][hash_key] = Array ('name'=>$name, 'path'=>$path, 'type'=>$type);
* Is a part of the authentication proces of the user.
* A final requirement for a path being mounted is that a) it MUST return TRUE on is_dir(), b) must contain either PATH_site+'fileadminDir' OR 'lockRootPath' - if lockRootPath is set - as first part of string!
* Paths in the mounted information will always be absolute and have a trailing slash.
*
* @param string $title Will be the (root)name of the filemount in the folder tree
* @param string $altTitle Will be the (root)name of the filemount IF $title is not TRUE (blank or zero)
* @param string $path Is the path which should be mounted. Will accept backslash in paths on windows servers (will substituted with forward slash). The path should be 1) relative to TYPO3_CONF_VARS[BE][fileadminDir] if $webspace is set, otherwise absolute.
* @param boolean $webspace If $webspace is set, the $path is relative to 'fileadminDir' in TYPO3_CONF_VARS, otherwise $path is absolute. 'fileadminDir' must be set to allow mounting of relative paths.
* @param string $type Type of filemount; Can be blank (regular) or "user" / "group" (for user and group filemounts presumably). Probably sets the icon first and foremost.
* @return boolean Returns "1" if the requested filemount was mounted, otherwise no return value.
* @deprecated since TYPO3 6.0, will be removed in TYPO3 6.1, all data is stored in $this->fileStorages now, see initializeFileStorages()
* @access private
* @todo Define visibility
*/
public function addFileMount($title, $altTitle, $path, $webspace, $type)
{
\TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
// Return FALSE if fileadminDir is not set and we try to mount a relative path
if ($webspace && !$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) {
return FALSE;
}
// Trimming and pre-processing
$path = trim($path);
// with WINDOWS convert backslash to slash!!
if ($this->OS == 'WIN') {
$path = str_replace('\\', '/', $path);
}
// If the path is TRUE and validates as a valid path string:
if ($path && \TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr($path)) {
// normalize path: remove leading '/' and './', and trailing '/' and '/.'
$path = trim($path);
$path = preg_replace('#^\\.?/|/\\.?$#', '', $path);
// There must be some chars in the path
if ($path) {
// Fileadmin dir, absolute
$fdir = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
if ($webspace) {
$path = $fdir . $path;
} else {
// With WINDOWS no prepending!!
if ($this->OS != 'WIN') {
// With WINDOWS no prepending!!
$path = '/' . $path;
}
}
$path .= '/';
// We now have a path with slash after and slash before (if unix)
if (@is_dir($path) && ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath']) || \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($path, $fdir))) {
// Alternative title?
$name = $title ? $title : $altTitle;
// Adds the filemount. The same filemount with same name, type and path cannot be set up twice because of the hash string used as key.
$this->groupData['filemounts'][md5($name . '|' . $path . '|' . $type)] = array('name' => $name, 'path' => $path, 'type' => $type);
// Return TRUE - went well, success!
return 1;
}
}
}
}
示例13: checkExtension
/**
* Check extension of given filename
*
* @param string $filename Filename like (upload.png)
* @return bool If Extension is allowed
*/
public static function checkExtension($filename)
{
$extensionList = 'jpg,jpeg,png,gif,bmp';
if (!empty($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_femanager.']['settings.']['misc.']['uploadFileExtension'])) {
$extensionList = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_femanager.']['settings.']['misc.']['uploadFileExtension'];
$extensionList = str_replace(' ', '', $extensionList);
}
$fileInfo = pathinfo($filename);
if (!empty($fileInfo['extension']) && GeneralUtility::inList($extensionList, strtolower($fileInfo['extension'])) && GeneralUtility::verifyFilenameAgainstDenyPattern($filename) && GeneralUtility::validPathStr($filename)) {
return TRUE;
}
return FALSE;
}
示例14: findRecycler
/**
* Goes back in the path and checks in each directory if a folder named $this->recyclerFN (usually '_recycler_') is present.
* If a folder in the tree happens to be a _recycler_-folder (which means that we're deleting something inside a _recycler_-folder) this is ignored
*
* @param string $theFile Takes a valid Path ($theFile)
* @return string Returns the path (without trailing slash) of the closest recycle-folder if found. Else FALSE.
* @todo To be put in Storage with a better concept
* @todo Define visibility
* @deprecated since TYPO3 6.0, use \TYPO3\CMS\Core\Resource\ResourceStorage method instead
*/
public function findRecycler($theFile)
{
GeneralUtility::logDeprecatedFunction();
if (GeneralUtility::validPathStr($theFile)) {
$theFile = \TYPO3\CMS\Core\Utility\PathUtility::getCanonicalPath($theFile);
$fI = GeneralUtility::split_fileref($theFile);
$c = 0;
// !!! Method has been put in the storage, can be saftely removed
$rDir = $fI['path'] . $this->recyclerFN;
while ($this->checkPathAgainstMounts($fI['path']) && $c < 20) {
if (@is_dir($rDir) && $this->recyclerFN != $fI['file']) {
return $rDir;
}
$theFile = $fI['path'];
$theFile = \TYPO3\CMS\Core\Utility\PathUtility::getCanonicalPath($theFile);
$fI = GeneralUtility::split_fileref($theFile);
$c++;
}
}
}
示例15: typo3conf_edit
/**
* Editing files in typo3conf directory (or elsewhere if enabled)
*
* @return void
* @todo Define visibility
*/
public function typo3conf_edit()
{
// default:
$EDIT_path = PATH_typo3conf;
if ($this->allowFileEditOutsite_typo3conf_dir && $this->INSTALL['FILE']['EDIT_path']) {
if (\TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr($this->INSTALL['FILE']['EDIT_path']) && substr($this->INSTALL['FILE']['EDIT_path'], -1) == '/') {
$tmp_path = PATH_site . $this->INSTALL['FILE']['EDIT_path'];
if (is_dir($tmp_path)) {
$EDIT_path = $tmp_path;
} else {
$this->errorMessages[] = '
\'' . $tmp_path . '\' was not directory
';
}
} else {
$this->errorMessages[] = '
Bad directory name (must be like t3lib/ or media/script/)
';
}
}
$headCode = 'Edit files in ' . basename($EDIT_path) . '/';
$messages = '';
if ($this->INSTALL['SAVE_FILE']) {
$save_to_file = $this->INSTALL['FILE']['name'];
if (@is_file($save_to_file)) {
$save_to_file_md5 = md5($save_to_file);
if (isset($this->INSTALL['FILE'][$save_to_file_md5]) && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($save_to_file, $EDIT_path . '') && substr($save_to_file, -1) != '~' && !strstr($save_to_file, '_bak')) {
$this->INSTALL['typo3conf_files'] = $save_to_file;
$save_fileContent = $this->INSTALL['FILE'][$save_to_file_md5];
if ($this->INSTALL['FILE']['win_to_unix_br']) {
$save_fileContent = str_replace(CRLF, LF, $save_fileContent);
}
$backupFile = $this->getBackupFilename($save_to_file);
if ($this->INSTALL['FILE']['backup']) {
if (@is_file($backupFile)) {
unlink($backupFile);
}
rename($save_to_file, $backupFile);
$messages .= '
Backup written to <strong>' . $backupFile . '</strong>
<br />
';
}
\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($save_to_file, $save_fileContent);
$messages .= '
File saved: <strong>' . $save_to_file . '</strong>
<br />
MD5-sum: ' . $this->INSTALL['FILE']['prevMD5'] . ' (prev)
<br />
MD5-sum: ' . md5($save_fileContent) . ' (new)
<br />
';
}
}
}
// Filelist:
// Get the template file
$templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'Typo3ConfEdit.html');
// Get the template part from the file
$template = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($templateFile, '###TEMPLATE###');
// Get the subpart for the files
$filesSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($template, '###FILES###');
$files = array();
$typo3conf_files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($EDIT_path, '', 1, 1);
$fileFound = 0;
foreach ($typo3conf_files as $k => $file) {
// Delete temp_CACHED files if option is set
if ($this->INSTALL['delTempCached'] && preg_match('|/temp_CACHED_[a-z0-9_]+\\.php|', $file)) {
unlink($file);
continue;
}
if ($this->INSTALL['typo3conf_files'] && !strcmp($this->INSTALL['typo3conf_files'], $file)) {
$fileFound = 1;
}
// Define the markers content for the files subpart
$filesMarkers = array('editUrl' => $this->action . '&TYPO3_INSTALL[typo3conf_files]=' . rawurlencode($file) . ($this->allowFileEditOutsite_typo3conf_dir ? '&TYPO3_INSTALL[FILE][EDIT_path]=' . rawurlencode($this->INSTALL['FILE']['EDIT_path']) : '') . '#confEditFileList', 'fileName' => basename($file), 'fileSize' => \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(filesize($file)), 'class' => $this->INSTALL['typo3conf_files'] && !strcmp($this->INSTALL['typo3conf_files'], $file) ? 'class="act"' : '');
// Fill the markers in the subpart
$files[] = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($filesSubpart, $filesMarkers, '###|###', TRUE, FALSE);
}
if ($fileFound && @is_file($this->INSTALL['typo3conf_files'])) {
$backupFile = $this->getBackupFilename($this->INSTALL['typo3conf_files']);
$fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($this->INSTALL['typo3conf_files']);
// Get the subpart to edit the files
$fileEditTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($template, '###FILEEDIT###');
$allowFileEditOutsideTypo3ConfDirSubPart = '';
if (substr($this->INSTALL['typo3conf_files'], -1) != '~' && !strstr($this->INSTALL['typo3conf_files'], '_bak')) {
// Get the subpart to show the save button
$showSaveButtonSubPart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($fileEditTemplate, '###SHOWSAVEBUTTON###');
}
if ($this->allowFileEditOutsite_typo3conf_dir) {
// Get the subpart to show if files are allowed outside the directory typo3conf
$allowFileEditOutsideTypo3ConfDirSubPart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($fileEditTemplate, '###ALLOWFILEEDITOUTSIDETYPO3CONFDIR###');
}
// Substitute the subpart for the save button
//.........这里部分代码省略.........