= 9) { return $fileArray; } // open directory if (!$fhd = @opendir($path)) { throw new Exception('directory "' . $path . '" cant be read'); } // iterate through the directory entries while ($file = readdir($fhd)) { $filePath = $path . '/' . $file; // ignore links and special directories (. and ..) if (preg_match('/^\.{1,2}$/', $file) || is_link($filePath)) { continue; } // if it's a file and not excluded by the search filter, we can add it // to the file array if (is_file($filePath)) { if ($searchRegex == '') { $fileArray[] = $filePath; } elseif (preg_match($searchRegex, $file)) { $fileArray[] = $filePath; } continue; } // next dir if (is_dir($filePath)) { $fileArray = array_merge( $fileArray, (array) SgLib::searchFiles($filePath, $searchRegex, $pathDepth + 1) ); } } closedir($fhd); return $fileArray; } /** * Returns all available system languages defined in TYPO3 * * @return array */ public static function getSystemLanguages() { /** @var Locales $locales */ $locales = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\Locales::class); $availableLanguageKeys = $locales->getLocales(); foreach ($availableLanguageKeys as $index => $language) { if ($language === 'default') { $availableLanguageKeys[$index] = 'default'; break; } } return $availableLanguageKeys; } /** * Convert special HTML characters to HTML entities, but ignores CDATA section. * * @param string $value * @return string */ public static function htmlSpecialCharsIgnoringCdata($value) { $cdataStart = strpos($value, ''); if ($cdataStart !== FALSE && $cdataEnd !== FALSE) { $cdataEnd += 3; $valueBefore = substr($value, 0, $cdataStart); $cdataValue = substr($value, $cdataStart, $cdataEnd - $cdataStart); $valueAfter = substr($value, $cdataEnd, strlen($value) - $cdataEnd); $value = htmlspecialchars($valueBefore) . '<![CDATA[' . $cdataValue . ']]>' . htmlspecialchars($valueAfter); } else { $value = htmlspecialchars($value); } return $value; } /** * Checks if CDATA tag exists in string. * * @param string $value * @return bool */ public static function checkForCdataInString($value) { $cdataStart = strpos($value, ''); return ($cdataStart !== FALSE && $cdataEnd !== FALSE); } /** * Writes at end of PHP file, just before php closing tag or at the end of file if php closing tag does not exist. * If specified file does not exist, it will be crated. * * @param string $filePath * @param string $lineToAdd * @return void */ public static function appendToPHPFile($filePath, $lineToAdd) { if (!is_file($filePath)) { $emptyPhpFileContent = ''; file_put_contents($filePath, $emptyPhpFileContent); } $configuration = file_get_contents($filePath); if ($configuration === FALSE) { return; } $phpEndTagPosition = strrpos($configuration, '?>'); if ($phpEndTagPosition) { $configuration = substr($configuration, 0, $phpEndTagPosition); } else { $configuration .= chr(0x0A); } $configuration .= chr(0x09) . $lineToAdd; if ($phpEndTagPosition) { $configuration .= chr(0x0A) . '?>'; } file_put_contents($filePath, $configuration); } /** * Compares two strings ignoring \r character and seeing \n as <br /> in first string. * * @param array|string $string1 * @param string $string2 * @return bool */ public static function strCmpIgnoreCR($string1, $string2) { return is_string($string1) && str_replace("\r", '', $string1) === $string2; } /** * Changes meta tag '@attributes' to 'attributes', if it exists. * * @param array $origMeta */ public static function fixMetaAttributes(array &$origMeta) { if (isset($origMeta['@attributes'])) { $origMeta['attributes'] = $origMeta['@attributes']; unset($origMeta['@attributes']); } } }