Skip to content
Snippets Groups Projects
Select Git revision
  • 10e1c97348f334846ea16262a5f8c6765e7e01e4
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

courseware-shelf-app.js

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    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
            );