<commit_before><?php

class rex_com_filebrowser
{

    private $path = '';
    private $file = '';
    private $admin = true;
    private $currentPath = '';
    private $fullPath;
    /** @type SplFileInfo[] */
    private $currentDirs = array();
    /** @type SplFileInfo[] */
    private $currentFiles = array();
    private $mimeTypes = array(
        'bmp' => 'mime-bmp.gif',
        'css' => 'mime-css.gif',
        'doc' => 'mime-doc.gif',
        'docx' => 'mime-docx.gif',
        'eps' => 'mime-eps.gif',
        'error' => 'mime-error.gif',
        'exe' => 'mime-exe.gif',
        'flv' => 'mime-flv.gif',
        'gif' => 'mime-gif.gif',
        'gz' => 'mime-gz.gif',
        'java' => 'mime-java.gif',
        'jpeg' => 'mime-jpeg.gif',
        'jpg' => 'mime-jpg.gif',
        'mov' => 'mime-mov.gif',
        'mp3' => 'mime-mp3.gif',
        'ogg' => 'mime-ogg.gif',
        'pdf' => 'mime-pdf.gif',
        'png' => 'mime-png.gif',
        'ppt' => 'mime-ppt.gif',
        'pptx' => 'mime-pptx.gif',
        'rtf' => 'mime-rtf.gif',
        'swf' => 'mime-swf.gif',
        'tar' => 'mime-tar.gif',
        'tif' => 'mime-tif.gif',
        'tiff' => 'mime-tiff.gif',
        'txt' => 'mime-txt.gif',
        'wma' => 'mime-wma.gif',
        'xls' => 'mime-xls.gif',
        'xlsx' => 'mime-xlsx.gif',
        'zip' => 'mime-zip.gif'
    );
    private $imageTypes = array('jpg', 'gif', 'jpeg', 'png', 'pdf');
    private $defaultSort = 'name-asc';


    function __construct($path = null)
    {
        $path = $path ?: rex_path::pluginData('community', 'filebrowser');
        rex_dir::create($path);
        $this->path = rtrim(realpath($path), '/');
        $this->setCurrentPath(rex_request('path', 'string'));
        $this->setCurrentFile(rex_request('file', 'string'));
        rex_login::startSession();
    }


    function setAdmin($admin = true)
    {
        $this->admin = $admin;
    }


    function isAdmin()
    {
        return $this->admin;
    }

    function setCurrentPath($current_path = '')
    {
        if ($this->isInRealm($current_path)) {
            $this->currentPath = $current_path;

        } else {
            $this->currentPath = '';

        }
        $this->fullPath = $this->path . $this->currentPath;
    }

    protected function isInRealm($path)
    {
        return $this->path == substr(realpath($this->path . '/' . $path), 0, strlen($this->path));
    }

    function setCurrentFile($file = '')
    {
        if ($this->isInRealm($this->getCurrentPath($file))) {
            $this->file = $file;
        } else {
            $this->file = '';
        }
        return $this->file;
    }


    function getCurrentPath($file = null)
    {
        return $this->currentPath . ($file ? '/' . $file : '');
    }

    function getFullPath($file = null)
    {
        return $this->fullPath . ($file ? '/' . $file : '');
    }

    public function setDefaultSort($type, $direction = 'asc')
    {
        $this->defaultSort = $type . '-' . $direction;
    }

    function scanDir()
    {
        $this->currentDirs = array();
        $this->currentFiles = array();

        foreach (rex_finder::factory($this->fullPath)->dirsOnly() as $dir) {
            $this->currentDirs[$this->getCurrentPath($dir->getBasename())] = $dir;
            uasort ( $this->currentDirs , function ($a, $b) {
                $a_name = basename($a);
                $b_name = basename($b);
                if ($a_name == $b_name) {
                  return 0;
                }
                return $a_name < $b_name ? -1 : 1;
            });
        }

        $sort = explode('-', rex_get('sort', 'string') ?: $this->defaultSort);
        $sort[1] = isset($sort[1]) ? $sort[1] : 'asc';
        $sortGetter = 'date' == $sort[0] ? 'getMTime' : 'getBasename';
        $finder = rex_finder::factory($this->fullPath)->filesOnly()->sort(function (SplFileInfo $a, SplFileInfo $b) use ($sort, $sortGetter) {
            $a = $a->$sortGetter();
            $b = $b->$sortGetter();
            if ($a == $b) {
                return 0;
            }
            if ('desc' == $sort[1]) {
                $temp = $a;
                $a = $b;
                $b = $temp;
            }
            if ('date' == $sort[0]) {
                return $a < $b ? -1 : 1;<commit_msg>filbrowser: sort geht wohl auch einfacher :)<commit_after><?php

class rex_com_filebrowser
{

    private $path = '';
    private $file = '';
    private $admin = true;
    private $currentPath = '';
    private $fullPath;
    /** @type SplFileInfo[] */
    private $currentDirs = array();
    /** @type SplFileInfo[] */
    private $currentFiles = array();
    private $mimeTypes = array(
        'bmp' => 'mime-bmp.gif',
        'css' => 'mime-css.gif',
        'doc' => 'mime-doc.gif',
        'docx' => 'mime-docx.gif',
        'eps' => 'mime-eps.gif',
        'error' => 'mime-error.gif',
        'exe' => 'mime-exe.gif',
        'flv' => 'mime-flv.gif',
        'gif' => 'mime-gif.gif',
        'gz' => 'mime-gz.gif',
        'java' => 'mime-java.gif',
        'jpeg' => 'mime-jpeg.gif',
        'jpg' => 'mime-jpg.gif',
        'mov' => 'mime-mov.gif',
        'mp3' => 'mime-mp3.gif',
        'ogg' => 'mime-ogg.gif',
        'pdf' => 'mime-pdf.gif',
        'png' => 'mime-png.gif',
        'ppt' => 'mime-ppt.gif',
        'pptx' => 'mime-pptx.gif',
        'rtf' => 'mime-rtf.gif',
        'swf' => 'mime-swf.gif',
        'tar' => 'mime-tar.gif',
        'tif' => 'mime-tif.gif',
        'tiff' => 'mime-tiff.gif',
        'txt' => 'mime-txt.gif',
        'wma' => 'mime-wma.gif',
        'xls' => 'mime-xls.gif',
        'xlsx' => 'mime-xlsx.gif',
        'zip' => 'mime-zip.gif'
    );
    private $imageTypes = array('jpg', 'gif', 'jpeg', 'png', 'pdf');
    private $defaultSort = 'name-asc';


    function __construct($path = null)
    {
        $path = $path ?: rex_path::pluginData('community', 'filebrowser');
        rex_dir::create($path);
        $this->path = rtrim(realpath($path), '/');
        $this->setCurrentPath(rex_request('path', 'string'));
        $this->setCurrentFile(rex_request('file', 'string'));
        rex_login::startSession();
    }


    function setAdmin($admin = true)
    {
        $this->admin = $admin;
    }


    function isAdmin()
    {
        return $this->admin;
    }

    function setCurrentPath($current_path = '')
    {
        if ($this->isInRealm($current_path)) {
            $this->currentPath = $current_path;

        } else {
            $this->currentPath = '';

        }
        $this->fullPath = $this->path . $this->currentPath;
    }

    protected function isInRealm($path)
    {
        return $this->path == substr(realpath($this->path . '/' . $path), 0, strlen($this->path));
    }

    function setCurrentFile($file = '')
    {
        if ($this->isInRealm($this->getCurrentPath($file))) {
            $this->file = $file;
        } else {
            $this->file = '';
        }
        return $this->file;
    }


    function getCurrentPath($file = null)
    {
        return $this->currentPath . ($file ? '/' . $file : '');
    }

    function getFullPath($file = null)
    {
        return $this->fullPath . ($file ? '/' . $file : '');
    }

    public function setDefaultSort($type, $direction = 'asc')
    {
        $this->defaultSort = $type . '-' . $direction;
    }

    function scanDir()
    {
        $this->currentDirs = array();
        $this->currentFiles = array();

        foreach (rex_finder::factory($this->fullPath)->dirsOnly()->sort() as $dir) {
            $this->currentDirs[$this->getCurrentPath($dir->getBasename())] = $dir;
        }

        $sort = explode('-', rex_get('sort', 'string') ?: $this->defaultSort);
        $sort[1] = isset($sort[1]) ? $sort[1] : 'asc';
        $sortGetter = 'date' == $sort[0] ? 'getMTime' : 'getBasename';
        $finder = rex_finder::factory($this->fullPath)->filesOnly()->sort(function (SplFileInfo $a, SplFileInfo $b) use ($sort, $sortGetter) {
            $a = $a->$sortGetter();
            $b = $b->$sortGetter();
            if ($a == $b) {
                return 0;
            }
            if ('desc' == $sort[1]) {
                $temp = $a;
                $a = $b;
                $b = $temp;
            }
            if ('date' == $sort[0]) {
                return $a < $b ? -1 : 1;
{'fraction_non_alphanumeric': 0.20438743706545193, 'fraction_numerical': 0.003236633900743227, 'mean_word_length': 1.8660254208175884, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3313995', 'n_tokens_mistral': 2953, 'n_tokens_neox': 2801, 'n_words': 492}