public static function getFolderForClass($class)
    {
        $folderName = 'Uploads';

        if (is_object($class)) {
            if (method_exists($class, 'hasMethod') && $class->hasMethod('BaseFolder')) {
                $folderName = $class->BaseFolder();
            }
            elseif ($class instanceof Page) {
                $folderName = get_class($class);
            }
            elseif ($class instanceof DataObject) {
                $folderName = $class->baseTable();
            }
            elseif ($class instanceof DataExtension) {
                $folderName = $class->getOwner()->baseTable();
            }
            else {
                $folderName = get_class($class);
            }
        }
        elseif (is_string($class)) {
            $folderName = $class;
        }

        if (class_exists('Subsite') && Config::inst()->get(
            __CLASS__,
            'use_subsite_integration'
        )) {
            $subsite = Subsite::currentSubsite();
            if ($subsite) {
                // Subsite extras integration$
                if ($subsite->hasField('BaseFolder')) {
                    $baseFolder = $subsite->BaseFolder;
                }
                else {
                    $filter = new URLSegmentFilter();
                    $baseFolder = $filter->filter($subsite->getTitle());
                    $baseFolder = str_replace(
                        ' ',
                        '',
                        ucwords(str_replace('-', ' ', $baseFolder))
                    );
                }
                if (!empty($baseFolder)) {
                    $folderName = $baseFolder . '/' . $folderName;
                }
            }
        }

        return $folderName;
    }