Returns an allowed filename and an extra field header

When encoding stuff outside the 7bit ASCII range it needs to be placed in a separate
extra field

@param $original
@return array($filename, $extra)
778964
protected function encodeFilename($original)
    {
        $cp437 = $this->utf8ToCp($original);
        if ($cp437 === $original) {
            return array($original, '');
        }

        $extra = pack(
            'vvCV',
            0x7075, // tag
            strlen($original) + 5, // length of file + version + crc
            1, // version
            crc32($original) // crc
        );
        $extra .= $original;

        return array($cp437, $extra);
    }
888266
public static function safeFilename($filename)
    {
        Deprecated::method(3.0);

        $filename = rawurlencode($filename); // Use 'rawurlencode', because we prefer '%20' over '+' for spaces.
        $filename = str_replace('%2F', '/', $filename);

        if (substr($filename, 0, 1) == '/') {
            $filename = substr($filename, 1);
        }

        return $filename;
    }
238135
function getBasename()
    {
        $filename  = $this->getFilename();
        $extension = $this->getExtension();

        return ($extension === '' || $extension === null)
            ? $filename
            : $filename.'.'.$extension;
    }
33188
public function getFilenameWithoutExtension()
    {
        $filename = $this->getDocument()->getFile()->getFilename();

        return substr($filename, 0, strrpos($filename, '.'));
    }
123407
public function getNameWithoutExtension($fileName)
    {
        $lastDot = strrpos($fileName, '.');

        if (!$lastDot) {
            return $fileName;
        }

        return substr($fileName, 0, $lastDot);
    }
987037
public function getFilename(string $key): string
    {
        if (!$this->validate($key)) {
            throw new \InvalidArgumentException('The key provided (' . $key . ') is not valid! It may contain only the following characters: "a-z", "0-9", ".", "/", "-" and "_".');
        }
        if ($this->filenameProtocol === null) {
            throw new \Exception('No filenameProtocol specified!');
        }
        return $this->filenameProtocol . '://' . $key;
    }
219128
public function getFilename($extension = '.php')
    {
        // If template is named,
        // return joined template names.
        if ($this->isNamed()) {
            return join('-', $this->file) . $extension;
        }

        // Use first template name, if template
        // file is an array, but is not named.
        if (is_array($this->file) && isset($this->file[0])) {
            return "{$this->file[0]}{$extension}";
        }

        return apply_filters('tonik/gin/template/filename', "{$this->file}{$extension}");
    }
202365
private function _encoded_filename()
    {
        $ext = strtolower(pathinfo($this->source_file, PATHINFO_EXTENSION));
        $encode = md5($this->source_file . http_build_query($this->url_params));
        
        // Build the parts of the filename
        $encoded_name = $encode . '-' . $this->source_modified . '.' . $ext;
        
        return $encoded_name;
    }
710642
public static function maybeUnSerialize($original)
    {
        if (! is_string($original) || trim($original) == '') {
            return $original;
        }

        /**
         * Check if serialized
         * check with trim
         */
        if (self::isSerialized($original)) {
            /**
             * use trim if possible
             * Serialized value could not start & end with white space
             */
            return @unserialize(trim($original));
        }

        return $original;
    }
874681
public function getFileDirPrefix($filename)
    {
        if (empty($filename)) {
            throw new InvalidArgumentException('Invalid filename argument');
        }

        $path = array();
        $parts = explode('.', $filename);

        for ($i = 0; $i < min(strlen($parts[0]), $this->prefixSize); $i++) {
            $path[] = $filename[$i];
        }

        $path = $this->getPath($path);

        return $path;
    }
1174401
public static function removeExtension($filename)
    {
        if (false === strrpos($filename, '.')) {
            return $filename;
        }

        return substr($filename, 0, strrpos($filename, '.'));
    }
1262459
public function getResultExtension(string $originalFileExtension = ''): string
    {
        if ($this->shouldKeepOriginalImageFormat()) {
            if (in_array($originalFileExtension, ['jpg', 'pjpg', 'png', 'gif'])) {
                return $originalFileExtension;
            }
        }

        if ($manipulationArgument = $this->manipulations->getManipulationArgument('format')) {
            return $manipulationArgument;
        }

        return $originalFileExtension;
    }
397915
protected function filterFilename($name)
    {
        // Fix illegal characters
        $filter = FileNameFilter::create();
        $parts = array_filter(preg_split("#[/\\\\]+#", $name));
        return implode('/', array_map(function ($part) use ($filter) {
            return $filter->filter($part);
        }, $parts));
    }
583718
protected function getUniqueFilename($fileName)
    {
        $returnValue = uniqid(hash('crc32', $fileName));
    
        $ext = @pathinfo($fileName, PATHINFO_EXTENSION);
        if (!empty($ext)){
            $returnValue .= '.' . $ext;
        }
    
        return $returnValue;
    }
758996
public static function getExtension($filename)
    {
        Deprecated::method(3.0, 'Use pathinfo() instead.');

        $pos = strrpos($filename, '.');
        if ($pos === false) {
            return '';
        }
        $ext = substr($filename, $pos + 1);

        return $ext;
    }
877197
public function getExt()
    {
        if (is_null($this->ext) && $this->originFile) {
            $file = basename($this->originFile);
            // Use substr instead of pathinfo, because pathinfo may return error value in unicode
            if (false !== $pos = strrpos($file, '.')) {
                $this->ext = strtolower(substr($file, $pos + 1));
            } else {
                $this->ext = '';
            }
        }
        return $this->ext;
    }
10019
public function getExtraFields()
    {
        if ($this->_extraFields === null) {
            $extraFields = [];
            foreach ($this->getConfig() as $pointer => $fields) {
                if (is_array($fields)) {
                    foreach ($fields as $field) {
                        if (isset($field['extraField']) && $field['extraField']) {
                            if (!array_key_exists($field['name'], $extraFields)) {
                                $extraFields[] = $field['name'];
                            }
                        }
                    }
                }
            }
            $this->_extraFields = $extraFields;
        }

        return $this->_extraFields;
    }