From a given path, work out what type of plugin
this belongs to
@param string $dirpath Path to the db file for this plugin
@return string the type of the plugin or null if not found
508806
function get_plugin_type($dirpath) {
        global $CFG;
        $dirpath = $CFG->dirroot.$dirpath;
        // Reverse order so that we get subplugin matches.
        $plugintypes = array_reverse(core_component::get_plugin_types());
        foreach ($plugintypes as $plugintype => $pluginbasedir) {
            if (substr($dirpath, 0, strlen($pluginbasedir)) == $pluginbasedir) {
                return $plugintype;
            }
        }
        return null;
    }
336999
protected function getConfigurationFiles($directoryPath)
    {
        $files = [];

        if (is_dir($directoryPath)) {
            foreach (Finder::create()->files()->in($directoryPath) as $file) {
                $group = basename($file->getRealPath(), '.php');
                $files[$group] = $file->getRealPath();
            }
        }

        return $files;
    }
925864
static public function emptyDir($dirpath)
    {
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirpath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
            $path->isFile() ? unlink($path->getPathname()) : rmdir($path->getPathname());
        }
    }
1024322
public function parsePath(?string $path = null): ?string
    {
        if ($path === null) {
            return null;
        }
        $path = \str_replace('%DOCUMENT_ROOT%', $this->documentRoot, $path);
        $path = \str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
        return $path;
    }
412524
private function packagePath(string $relativePath): string
    {
    	$packagePath = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $this->packagePath), DIRECTORY_SEPARATOR);
        $relativePath = ltrim(str_replace('/', DIRECTORY_SEPARATOR, $relativePath), DIRECTORY_SEPARATOR);

        return realpath($packagePath . DIRECTORY_SEPARATOR . $relativePath);
    }
884779
public function path($path = null)
    {
        if ($path !== null) {
            $this->path = $path;
        }

        return (string) $this->path;
    }
619551
public function find(string $templatePath)
    {
        foreach ($this->paths as $path) {
            $filePath = sprintf(
                '%s/%s',
                rtrim($path, '/'),
                ltrim($templatePath, '/')
            );

            if (is_file($filePath)) {
                return $filePath;
            }
        }

        return null;
    }
792091
public function rootPath($path = '')
    {
        if (defined('THEMOSIS_ROOT')) {
            return THEMOSIS_ROOT.($path ? DIRECTORY_SEPARATOR.$path : $path);
        }

        return $this->webPath($path);
    }
3020
protected function dirname($path)
    {
        if (is_file($path)) {
            return dirname($path);
        }

        if (is_dir($path)) {
            return rtrim($path, '/');
        }

        // no known file/dir, start making assumptions

        // ends in / = dir
        if (mb_substr($path, -1) === '/') {
            return rtrim($path, '/');
        }

        // has a dot in the name, likely a file
        if (preg_match('/.*\..*$/', basename($path)) !== 0) {
            return dirname($path);
        }

        // you're on your own here!
        return $path;
    }
1195329
protected function parsePath($path = null)
    {
        $this->dirname   = '';
        $this->basename  = '';
        $this->extension = '';
        $this->filename  = '';

        if (empty($path)) {
            return $this;
        }

        $parts = pathinfo($path);

        if (isset($parts['dirname'])) {
            $this->dirname = rtrim($parts['dirname'], '/');
        }

        if (isset($parts['basename'])) {
            $this->basename = $parts['basename'];
        }

        if (isset($parts['extension'])) {
            $this->extension = $parts['extension'];
        }

        if (isset($parts['filename'])) {
            $this->filename = $parts['filename'];
        }

        return $this;
    }
73478
public function path($moduleFilePath = null)
    {
        if ($moduleFilePath !== null) {
            $this->_path = dirname($moduleFilePath);
        }
        return $this->_path;
    }
907332
protected static function getMimetypeFromLocalFilePath($filePath) {
		$mimetype = getMimeType($filePath);
		if( $mimetype !== 'text/plain' ) {
			return $mimetype;
		}
		return static::getMimetypeFromExtension(pathinfo($filePath, PATHINFO_EXTENSION));
	}
325430
public function findPath($classname, $basepath = null)
    {
        $path = false;

        $word  = strtolower(preg_replace('/(?<=\\w)([A-Z])/', ' \\1', $classname));
        $parts = explode(' ', $word);

        if (array_shift($parts) == 'plg') {
            //Switch the basepath
            if (!empty($basepath)) {
                $this->_basepath = $basepath;
            }

            $type = array_shift($parts);

            if (count($parts) > 1) {
                $path = array_shift($parts).'/'.implode('/', $parts);
            } else {
                $path = array_shift($parts);
            }

            //Plugins can have their own folder
            if (is_file($this->_basepath.'/plugins/'.$type.'/'.$path.'/'.$path.'.php')) {
                $path = $this->_basepath.'/plugins/'.$type.'/'.$path.'/'.$path.'.php';
            } else {
                $path = $this->_basepath.'/plugins/'.$type.'/'.$path.'.php';
            }
        }

        return $path;
    }
972456
public static function enumPHPFile($dirPath)
    {
        if (!is_dir($dirPath)) {
            return new \ArrayIterator();
        }
        $directory = new \RecursiveDirectoryIterator($dirPath);
        $iterator = new \RecursiveIteratorIterator($directory);
        $regex = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH);
        return $regex;
    }
227413
public function getFolder( $dirName )
	{
		if( !$this->numFolders )
			return NULL;
		foreach( $this->folders as $key => $information )
			if( $information['name'] == $dirName )
				return $information;
	}
864350
public function app_path($path = null)
    {
        return empty($path) ? $this->base_path() . DIRECTORY_SEPARATOR . 'app' : $this->base_path() . 'app' . $path;
    }
295055
public function getRoutesPath($basePath = null)
    {
        $routes = $this->get('routes');
        if (empty($routes)) {
            // Fallback to default
            return $basePath . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'main.php';
        }

        return $basePath . DIRECTORY_SEPARATOR . $routes['base_dir'] . DIRECTORY_SEPARATOR . $routes['base_file'];
    }