From 6db6689740a5d11dd53b2502d1eea6e9157479df Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 9 Apr 2015 15:19:57 +0200 Subject: Added mimetype detector * Copied unit tests from old functions --- lib/public/files/imimetypedetector.php | 78 ++++++++++++++++++++++++++++++++++ lib/public/iservercontainer.php | 9 ++++ 2 files changed, 87 insertions(+) create mode 100644 lib/public/files/imimetypedetector.php (limited to 'lib/public') diff --git a/lib/public/files/imimetypedetector.php b/lib/public/files/imimetypedetector.php new file mode 100644 index 00000000000..79ed8a4fac9 --- /dev/null +++ b/lib/public/files/imimetypedetector.php @@ -0,0 +1,78 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + + +/** + * Interface IMimeTypeDetector + * @package OCP\Files + * @since 8.2.0 + * + * Interface to handle mimetypes (detection and icon retrieval) + **/ +interface IMimeTypeDetector { + + /** + * detect mimetype only based on filename, content of file is not used + * @param string $path + * @return string + * @since 8.2.0 + **/ + public function detectPath($path); + + /** + * detect mimetype based on both filename and content + * + * @param string $path + * @return string + * @since 8.2.0 + */ + public function detect($path); + + /** + * Get a secure mimetype that won't expose potential XSS. + * + * @param string $mimeType + * @return string + * @since 8.2.0 + */ + public function getSecureMimeType($mimeType); + + /** + * detect mimetype based on the content of a string + * + * @param string $data + * @return string + * @since 8.2.0 + */ + public function detectString($data); + + /** + * Get path to the icon of a file type + * @param string $mimeType the MIME type + * @return string the url + * @since 8.2.0 + */ + public function mimeTypeIcon($mimeType); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 95ee853d84c..f3165db33da 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -9,6 +9,7 @@ * @author Lukas Reschke * @author Morris Jobke * @author Robin Appelman + * @author Roeland Jago Douma * @author Thomas Müller * @author Thomas Tanghus * @@ -429,4 +430,12 @@ interface IServerContainer { * @since 8.2.0 */ public function getMountManager(); + + /** + * Get the MimeTypeDetector + * + * @return \OCP\Files\IMimeTypeDetector + * @since 8.2.0 + */ + public function getMimeTypeDetector(); } -- cgit v1.2.3