Select Git revision
courseware-shelf-app.js
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
Marcus Eibrink-Lunzenauer authored
Closes #2482 Merge request studip/studip!1788
Marcus Eibrink-Lunzenauer authoredCloses #2482 Merge request studip/studip!1788
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
FileManager.php 72.15 KiB
<?php
/**
* FileManager.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author André Noack <noack@data-quest.de>
* @author Moritz Strohm <strohm@data-quest.de>
* @copyright 2016 Stud.IP Core-Group
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
/**
* The FileManager class contains methods that faciliate the management of files
* and folders. Furthermore its methods perform necessary additional checks
* so that files and folders are managed in a correct manner.
*
* It is recommended to use the methods of this class for file and folder
* management instead of writing own methods.
*/
class FileManager
{
//FILE HELPER METHODS
/**
* Removes special characters from the file name (and by that cleaning
* the file name) so that the file name which is returned by this method
* works on every operating system.
*
* @param string $file_name The file name that shall be "cleaned".
* @param bool $shorten_name True, if the file name shall be shortened to
* 31 characters. False, if the full length shall be kept (default).
*
* @return string The "cleaned" file name.
*/
public static function cleanFileName($file_name = null, $shorten_name = false)
{
if(!$file_name) {
//If you put an empty string in, you will get an empty string out!
return $file_name;
}
$bad_characters = [
':', chr(92), '/', '"', '>', '<', '*', '|', '?',
' ', '(', ')', '&', '[', ']', '#', chr(36), '\'',
'*', ';', '^', '`', '{', '}', '|', '~', chr(255)
];
$replacement_characters = [
'', '', '', '', '', '', '', '', '',
'_', '', '', '+', '', '', '', '', '',
'', '-', '', '', '', '', '-', '', ''
];
//All control characters shall be deleted:
for($i = 0; $i < 0x20; $i++) {
$bad_characters[] = chr($i);
$replacement_characters[] = '';
}
$clean_file_name = str_replace(
$bad_characters,
$replacement_characters,
$file_name
);