Convert file name from system encoding into UTF-8

@static
@access public
@param string $fileName
@return string
545046
public static function convertToConnectorEncoding($fileName)
    {
        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
        $encoding = $_config->getFilesystemEncoding();
        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
            return $fileName;
        }

        if (!function_exists("iconv")) {
            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
                return utf8_encode($fileName);
            } else {
                return $fileName;
            }
        }

        $converted = @iconv($encoding, "UTF-8", $fileName);

        if ($converted === false) {
            return $fileName;
        }

        return $converted;
    }
403575
public function fetch($filename): string {
        $data = file_get_contents($this->_getFilePath($filename));
        if ($this->_gzip) {
            $probablyGzipped = bin2hex(substr($data, 0, 2)) == '1f8b';
            $data = $probablyGzipped ? gzdecode($data) : $data;
        }
        return $data;
    }
407887
protected static function getXmlFilename($filename) {
        if ( strpos($filename, '/') === false ) {
            $filename = APP_PATH."build/{$filename}";
        }
        if ( strpos($filename, '.xml') === false ) {
            $filename .= ".xml";
        }
        return $filename;
    }
1169420
private function parseFilename($filename) {
    if (defined('DRUPAL_ROOT') && stripos($filename, DRUPAL_ROOT) === 0) {
      return substr($filename, strpos($filename, DRUPAL_ROOT) + strlen(DRUPAL_ROOT) + 1);
    }
    else {
      return $filename;
    }
  }
969891
public function setFilename($filename)
    {
        $this->throwExceptionIfProtected();

        $pathInfo = UnicodeFunctions::pathinfo($filename);
        $extension = (isset($pathInfo['extension']) ? '.' . strtolower($pathInfo['extension']) : '');
        $this->filename = $pathInfo['filename'] . $extension;
        $this->mediaType = Utility\MediaTypes::getMediaTypeFromFilename($this->filename);
    }
400137
protected static function iterateFileName(string $fileName)
    {
        //First remove Extension
        $arrFileParts = explode(".", $fileName);
        $extension = array_pop($arrFileParts);
        $tempFileName = implode(".", $arrFileParts);
        $arrFileName = explode("_", $tempFileName);
        if (is_numeric($arrFileName[(count($arrFileName) - 1)])) {
            $iterator = (int) array_pop($arrFileName);
            $iterator++;
            $arrFileName[] = $iterator;
            $newFileName = implode("_", $arrFileName);
            return $newFileName . "." . $extension;
        }
        return $tempFileName."_1." . $extension;
    }
1347974
public static function getMimetype($filename): string
    {
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        $extension = strtolower($extension);
        return !empty(self::$mimetypes[$extension]) ? self::$mimetypes[$extension] : '';
    }
803187
public static function removeExtension($fileName) {
		$ext = strrchr($fileName, '.');
		if($ext !== false) {
			$fileName = substr($fileName, 0, -strlen($ext));
		}
		return $fileName;
	}
202824
public function makeValidFileName($sFilename)
    {
        $sFilename = preg_replace('/[\s]+/', '_', $sFilename);
        $sFilename = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $sFilename);

        return str_replace(' ', '_', $sFilename);
    }
812734
def decode_filename(filename):
    """"""
    if isinstance(filename, unicode):
        return filename

    return filename.decode(sys.getfilesystemencoding())
768645
protected function cleanupName($filename)
    {
        $filename = str_replace(array('/', '\\', ':', ' '), '_', $filename);
        // Remove dot if it starts with one
        $filename = trim($filename, '.');

        return \MUtil_File::cleanupName($filename);
    }
841234
public function persian_Slug_Format($filename) {
		$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'","\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));
		$filename = str_replace($special_chars, '', $filename);
		$filename = preg_replace('/[\s-]+/', '-', $filename);
		$filename = trim($filename, '.-_');
		return $filename;
	}
1193548
public function getFileName($fileName, $ext='')
    {
        if (empty($ext)) {
            $fileName= substr($fileName, 0, strrpos($fileName, '.', -1));
        }
        else {
            if (substr($ext, 0, 1)!='.') {
                $ext= '.'.$ext;
            }

            if (substr($fileName, -(strlen($ext)))==$ext) {
                $fileName= substr($fileName, 0, -(strlen($ext)));
            }
        }

        $exFileName = explode('/', Utils\Util::toFormat($fileName, '/'));

        return end($exFileName);
    }
892647
public static function sanitizeFilename($filename) {
        $filename = (string) $filename;

        $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]", "}", "\\", "|", ";", ":", "\"", "'",
            "&#8216;", "&#8217;", "&#8220;", "&#8221;", "&#8211;", "&#8212;", "â€”", "â€“", ",", "<", ">", "/", "?", "\0");
        $clean = trim(str_replace($strip, '', $filename));
        $clean = preg_replace('/\s+/', "-", $clean);
        if (empty($clean)) {
            throw new CM_Exception_Invalid('Invalid filename.');
        }
        return $clean;
    }
601675
protected function checkIfFileNameIsSafe(string $fileName)
    {
        $allowedFileNames = $this->getLanguageFiles(true);

        if (!in_array($fileName, $allowedFileNames)) {
            return false;
        }

        return true;
    }
478873
static function filenameWithoutExtension($filename) {
		$filename=self::filename($filename);
		if (preg_match('~(.*)\.(\w{1,10})$~',$filename,$parts)) {
			return $parts[1];
		}
		return $filename;
	}
1161875
public static function getClassFromFileName($filename)
    {
        $filename = basename($filename);

        $rpos = strrpos($filename, '.');

        if ($rpos != -1) {
            $filename = substr($filename, 0, $rpos);
        }

        return $filename;
    }