Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,307 @@
<?php
/**
* @file
* Contains \Drupal\Core\File\FileSystem.
*/
namespace Drupal\Core\File;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Psr\Log\LoggerInterface;
/**
* Provides helpers to operate on files and stream wrappers.
*/
class FileSystem implements FileSystemInterface {
/**
* Default mode for new directories. See self::chmod().
*/
const CHMOD_DIRECTORY = 0775;
/**
* Default mode for new files. See self::chmod().
*/
const CHMOD_FILE = 0664;
/**
* The site settings.
*
* @var \Drupal\Core\Site\Settings
*/
protected $settings;
/**
* The file logger channel.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The stream wrapper manager.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;
/**
* Constructs a new FileSystem.
*
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The stream wrapper manager.
* @param \Drupal\Core\Site\Settings $settings
* The site settings.
* @param \Psr\Log\LoggerInterface $logger
* The file logger channel.
*/
public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager, Settings $settings, LoggerInterface $logger) {
$this->streamWrapperManager = $stream_wrapper_manager;
$this->settings = $settings;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function moveUploadedFile($filename, $uri) {
$result = @move_uploaded_file($filename, $uri);
// PHP's move_uploaded_file() does not properly support streams if
// open_basedir is enabled so if the move failed, try finding a real path
// and retry the move operation.
if (!$result) {
if ($realpath = $this->realpath($uri)) {
$result = move_uploaded_file($filename, $realpath);
}
else {
$result = move_uploaded_file($filename, $uri);
}
}
return $result;
}
/**
* {@inheritdoc}
*/
public function chmod($uri, $mode = NULL) {
if (!isset($mode)) {
if (is_dir($uri)) {
$mode = $this->settings->get('file_chmod_directory', static::CHMOD_DIRECTORY);
}
else {
$mode = $this->settings->get('file_chmod_file', static::CHMOD_FILE);
}
}
if (@chmod($uri, $mode)) {
return TRUE;
}
$this->logger->error('The file permissions could not be set on %uri.', array('%uri' => $uri));
return FALSE;
}
/**
* {@inheritdoc}
*/
public function unlink($uri, $context = NULL) {
$scheme = $this->uriScheme($uri);
if (!$this->validScheme($scheme) && (substr(PHP_OS, 0, 3) == 'WIN')) {
chmod($uri, 0600);
}
if ($context) {
return unlink($uri, $context);
}
else {
return unlink($uri);
}
}
/**
* {@inheritdoc}
*/
public function realpath($uri) {
// If this URI is a stream, pass it off to the appropriate stream wrapper.
// Otherwise, attempt PHP's realpath. This allows use of this method even
// for unmanaged files outside of the stream wrapper interface.
if ($wrapper = $this->streamWrapperManager->getViaUri($uri)) {
return $wrapper->realpath();
}
return realpath($uri);
}
/**
* {@inheritdoc}
*/
public function dirname($uri) {
$scheme = $this->uriScheme($uri);
if ($this->validScheme($scheme)) {
return $this->streamWrapperManager->getViaScheme($scheme)->dirname($uri);
}
else {
return dirname($uri);
}
}
/**
* {@inheritdoc}
*/
public function basename($uri, $suffix = NULL) {
$separators = '/';
if (DIRECTORY_SEPARATOR != '/') {
// For Windows OS add special separator.
$separators .= DIRECTORY_SEPARATOR;
}
// Remove right-most slashes when $uri points to directory.
$uri = rtrim($uri, $separators);
// Returns the trailing part of the $uri starting after one of the directory
// separators.
$filename = preg_match('@[^' . preg_quote($separators, '@') . ']+$@', $uri, $matches) ? $matches[0] : '';
// Cuts off a suffix from the filename.
if ($suffix) {
$filename = preg_replace('@' . preg_quote($suffix, '@') . '$@', '', $filename);
}
return $filename;
}
/**
* {@inheritdoc}
*/
public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
if (!isset($mode)) {
$mode = $this->settings->get('file_chmod_directory', static::CHMOD_DIRECTORY);
}
// If the URI has a scheme, don't override the umask - schemes can handle
// this issue in their own implementation.
if ($this->uriScheme($uri)) {
return $this->mkdirCall($uri, $mode, $recursive, $context);
}
// If recursive, create each missing component of the parent directory
// individually and set the mode explicitly to override the umask.
if ($recursive) {
// Ensure the path is using DIRECTORY_SEPARATOR.
$uri = str_replace('/', DIRECTORY_SEPARATOR, $uri);
// Determine the components of the path.
$components = explode(DIRECTORY_SEPARATOR, $uri);
// If the filepath is absolute the first component will be empty as there
// will be nothing before the first slash.
if ($components[0] == '') {
$recursive_path = DIRECTORY_SEPARATOR;
// Get rid of the empty first component.
array_shift($components);
}
else {
$recursive_path = '';
}
// Don't handle the top-level directory in this loop.
array_pop($components);
// Create each component if necessary.
foreach ($components as $component) {
$recursive_path .= $component;
if (!file_exists($recursive_path)) {
if (!$this->mkdirCall($recursive_path, $mode, FALSE, $context)) {
return FALSE;
}
// Not necessary to use self::chmod() as there is no scheme.
if (!chmod($recursive_path, $mode)) {
return FALSE;
}
}
$recursive_path .= DIRECTORY_SEPARATOR;
}
}
// Do not check if the top-level directory already exists, as this condition
// must cause this function to fail.
if (!$this->mkdirCall($uri, $mode, FALSE, $context)) {
return FALSE;
}
// Not necessary to use self::chmod() as there is no scheme.
return chmod($uri, $mode);
}
/**
* Helper function. Ensures we don't pass a NULL as a context resource to
* mkdir().
*
* @see self::mkdir()
*/
protected function mkdirCall($uri, $mode, $recursive, $context) {
if (is_null($context)) {
return mkdir($uri, $mode, $recursive);
}
else {
return mkdir($uri, $mode, $recursive, $context);
}
}
/**
* {@inheritdoc}
*/
public function rmdir($uri, $context = NULL) {
$scheme = $this->uriScheme($uri);
if (!$this->validScheme($scheme) && (substr(PHP_OS, 0, 3) == 'WIN')) {
chmod($uri, 0700);
}
if ($context) {
return rmdir($uri, $context);
}
else {
return rmdir($uri);
}
}
/**
* {@inheritdoc}
*/
public function tempnam($directory, $prefix) {
$scheme = $this->uriScheme($directory);
if ($this->validScheme($scheme)) {
$wrapper = $this->streamWrapperManager->getViaScheme($scheme);
if ($filename = tempnam($wrapper->getDirectoryPath(), $prefix)) {
return $scheme . '://' . static::basename($filename);
}
else {
return FALSE;
}
}
else {
// Handle as a normal tempnam() call.
return tempnam($directory, $prefix);
}
}
/**
* {@inheritdoc}
*/
public function uriScheme($uri) {
if (preg_match('/^([\w\-]+):\/\/|^(data):/', $uri, $matches)) {
// The scheme will always be the last element in the matches array.
return array_pop($matches);
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function validScheme($scheme) {
if (!$scheme) {
return FALSE;
}
return class_exists($this->streamWrapperManager->getClass($scheme));
}
}

View file

@ -0,0 +1,245 @@
<?php
/**
* @file
* Contains \Drupal\Core\File\FileSystemInterface.
*/
namespace Drupal\Core\File;
/**
* Provides an interface for helpers that operate on files and stream wrappers.
*/
interface FileSystemInterface {
/**
* Moves an uploaded file to a new location.
*
* PHP's move_uploaded_file() does not properly support streams if
* open_basedir is enabled, so this function fills that gap.
*
* Compatibility: normal paths and stream wrappers.
*
* @param string $filename
* The filename of the uploaded file.
* @param string $uri
* A string containing the destination URI of the file.
*
* @return bool
* TRUE on success, or FALSE on failure.
*
* @see move_uploaded_file()
* @see https://www.drupal.org/node/515192
* @ingroup php_wrappers
*/
public function moveUploadedFile($filename, $uri);
/**
* Sets the permissions on a file or directory.
*
* This function will use the file_chmod_directory and
* file_chmod_file settings for the default modes for directories
* and uploaded/generated files. By default these will give everyone read
* access so that users accessing the files with a user account without the
* webserver group (e.g. via FTP) can read these files, and give group write
* permissions so webserver group members (e.g. a vhost account) can alter
* files uploaded and owned by the webserver.
*
* PHP's chmod does not support stream wrappers so we use our wrapper
* implementation which interfaces with chmod() by default. Contrib wrappers
* may override this behavior in their implementations as needed.
*
* @param string $uri
* A string containing a URI file, or directory path.
* @param int $mode
* Integer value for the permissions. Consult PHP chmod() documentation for
* more information.
*
* @return bool
* TRUE for success, FALSE in the event of an error.
*
* @ingroup php_wrappers
*/
public function chmod($uri, $mode = NULL);
/**
* Deletes a file.
*
* PHP's unlink() is broken on Windows, as it can fail to remove a file when
* it has a read-only flag set.
*
* @param string $uri
* A URI or pathname.
* @param resource $context
* Refer to http://php.net/manual/ref.stream.php
*
* @return bool
* Boolean TRUE on success, or FALSE on failure.
*
* @see unlink()
* @ingroup php_wrappers
*/
public function unlink($uri, $context = NULL);
/**
* Resolves the absolute filepath of a local URI or filepath.
*
* The use of this method is discouraged, because it does not work for
* remote URIs. Except in rare cases, URIs should not be manually resolved.
*
* Only use this function if you know that the stream wrapper in the URI uses
* the local file system, and you need to pass an absolute path to a function
* that is incompatible with stream URIs.
*
* @param string $uri
* A stream wrapper URI or a filepath, possibly including one or more
* symbolic links.
*
* @return string|false
* The absolute local filepath (with no symbolic links) or FALSE on failure.
*
* @see \Drupal\Core\StreamWrapper\StreamWrapperInterface::realpath()
* @see http://php.net/manual/function.realpath.php
* @ingroup php_wrappers
*/
public function realpath($uri);
/**
* Gets the name of the directory from a given path.
*
* PHP's dirname() does not properly pass streams, so this function fills that
* gap. It is backwards compatible with normal paths and will use PHP's
* dirname() as a fallback.
*
* Compatibility: normal paths and stream wrappers.
*
* @param string $uri
* A URI or path.
*
* @return string
* A string containing the directory name.
*
* @see dirname()
* @see https://www.drupal.org/node/515192
* @ingroup php_wrappers
*/
public function dirname($uri);
/**
* Gets the filename from a given path.
*
* PHP's basename() does not properly support streams or filenames beginning
* with a non-US-ASCII character.
*
* @see http://bugs.php.net/bug.php?id=37738
* @see basename()
*
* @ingroup php_wrappers
*/
public function basename($uri, $suffix = NULL);
/**
* Creates a directory, optionally creating missing components in the path to
* the directory.
*
* When PHP's mkdir() creates a directory, the requested mode is affected by
* the process's umask. This function overrides the umask and sets the mode
* explicitly for all directory components created.
*
* @param string $uri
* A URI or pathname.
* @param int $mode
* Mode given to created directories. Defaults to the directory mode
* configured in the Drupal installation. It must have a leading zero.
* @param bool $recursive
* Create directories recursively, defaults to FALSE. Cannot work with a
* mode which denies writing or execution to the owner of the process.
* @param resource $context
* Refer to http://php.net/manual/ref.stream.php
*
* @return bool
* Boolean TRUE on success, or FALSE on failure.
*
* @see mkdir()
* @see https://www.drupal.org/node/515192
* @ingroup php_wrappers
*
* @todo Update with open_basedir compatible recursion logic from
* \Drupal\Component\PhpStorage\FileStorage::ensureDirectory().
*/
public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL);
/**
* Removes a directory.
*
* PHP's rmdir() is broken on Windows, as it can fail to remove a directory
* when it has a read-only flag set.
*
* @param string $uri
* A URI or pathname.
* @param resource $context
* Refer to http://php.net/manual/ref.stream.php
*
* @return bool
* Boolean TRUE on success, or FALSE on failure.
*
* @see rmdir()
* @ingroup php_wrappers
*/
public function rmdir($uri, $context = NULL);
/**
* Creates a file with a unique filename in the specified directory.
*
* PHP's tempnam() does not return a URI like we want. This function will
* return a URI if given a URI, or it will return a filepath if given a
* filepath.
*
* Compatibility: normal paths and stream wrappers.
*
* @param string $directory
* The directory where the temporary filename will be created.
* @param string $prefix
* The prefix of the generated temporary filename.
* Note: Windows uses only the first three characters of prefix.
*
* @return string|bool
* The new temporary filename, or FALSE on failure.
*
* @see tempnam()
* @see https://www.drupal.org/node/515192
* @ingroup php_wrappers
*/
public function tempnam($directory, $prefix);
/**
* Returns the scheme of a URI (e.g. a stream).
*
* @param string $uri
* A stream, referenced as "scheme://target" or "data:target".
*
* @return string|bool
* A string containing the name of the scheme, or FALSE if none. For
* example, the URI "public://example.txt" would return "public".
*
* @see file_uri_target()
*/
public function uriScheme($uri);
/**
* Checks that the scheme of a stream URI is valid.
*
* Confirms that there is a registered stream handler for the provided scheme
* and that it is callable. This is useful if you want to confirm a valid
* scheme without creating a new instance of the registered handler.
*
* @param string $scheme
* A URI scheme, a stream is referenced as "scheme://target".
*
* @return bool
* Returns TRUE if the string is the name of a validated stream, or FALSE if
* the scheme does not have a registered handler.
*/
public function validScheme($scheme);
}

View file

@ -0,0 +1,933 @@
<?php
/**
* @file
* Contains \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser.
*/
namespace Drupal\Core\File\MimeType;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
/**
* Makes possible to guess the MIME type of a file using its extension.
*/
class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface {
/**
* Default MIME extension mapping.
*
* @var array
* Array of mimetypes correlated to the extensions that relate to them.
*/
protected $defaultMapping = array(
'mimetypes' => array(
0 => 'application/andrew-inset',
1 => 'application/atom',
2 => 'application/atomcat+xml',
3 => 'application/atomserv+xml',
4 => 'application/cap',
5 => 'application/cu-seeme',
6 => 'application/dsptype',
350 => 'application/epub+zip',
7 => 'application/hta',
8 => 'application/java-archive',
9 => 'application/java-serialized-object',
10 => 'application/java-vm',
11 => 'application/mac-binhex40',
12 => 'application/mathematica',
13 => 'application/msaccess',
14 => 'application/msword',
15 => 'application/octet-stream',
16 => 'application/oda',
17 => 'application/ogg',
18 => 'application/pdf',
19 => 'application/pgp-keys',
20 => 'application/pgp-signature',
21 => 'application/pics-rules',
22 => 'application/postscript',
23 => 'application/rar',
24 => 'application/rdf+xml',
25 => 'application/rss+xml',
26 => 'application/rtf',
27 => 'application/smil',
349 => 'application/vnd.amazon.ebook',
28 => 'application/vnd.cinderella',
29 => 'application/vnd.google-earth.kml+xml',
30 => 'application/vnd.google-earth.kmz',
31 => 'application/vnd.mozilla.xul+xml',
32 => 'application/vnd.ms-excel',
33 => 'application/vnd.ms-excel.addin.macroEnabled.12',
34 => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
35 => 'application/vnd.ms-excel.sheet.macroEnabled.12',
36 => 'application/vnd.ms-excel.template.macroEnabled.12',
37 => 'application/vnd.ms-pki.seccat',
38 => 'application/vnd.ms-pki.stl',
39 => 'application/vnd.ms-powerpoint',
40 => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
41 => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
42 => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
43 => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
44 => 'application/vnd.ms-word.document.macroEnabled.12',
45 => 'application/vnd.ms-word.template.macroEnabled.12',
46 => 'application/vnd.ms-xpsdocument',
47 => 'application/vnd.oasis.opendocument.chart',
48 => 'application/vnd.oasis.opendocument.database',
49 => 'application/vnd.oasis.opendocument.formula',
50 => 'application/vnd.oasis.opendocument.graphics',
51 => 'application/vnd.oasis.opendocument.graphics-template',
52 => 'application/vnd.oasis.opendocument.image',
53 => 'application/vnd.oasis.opendocument.presentation',
54 => 'application/vnd.oasis.opendocument.presentation-template',
55 => 'application/vnd.oasis.opendocument.spreadsheet',
56 => 'application/vnd.oasis.opendocument.spreadsheet-template',
57 => 'application/vnd.oasis.opendocument.text',
58 => 'application/vnd.oasis.opendocument.text-master',
59 => 'application/vnd.oasis.opendocument.text-template',
60 => 'application/vnd.oasis.opendocument.text-web',
61 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
62 => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
63 => 'application/vnd.openxmlformats-officedocument.presentationml.template',
64 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
65 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
66 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
67 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
68 => 'application/vnd.rim.cod',
69 => 'application/vnd.smaf',
70 => 'application/vnd.stardivision.calc',
71 => 'application/vnd.stardivision.chart',
72 => 'application/vnd.stardivision.draw',
73 => 'application/vnd.stardivision.impress',
74 => 'application/vnd.stardivision.math',
75 => 'application/vnd.stardivision.writer',
76 => 'application/vnd.stardivision.writer-global',
77 => 'application/vnd.sun.xml.calc',
78 => 'application/vnd.sun.xml.calc.template',
79 => 'application/vnd.sun.xml.draw',
80 => 'application/vnd.sun.xml.draw.template',
81 => 'application/vnd.sun.xml.impress',
82 => 'application/vnd.sun.xml.impress.template',
83 => 'application/vnd.sun.xml.math',
84 => 'application/vnd.sun.xml.writer',
85 => 'application/vnd.sun.xml.writer.global',
86 => 'application/vnd.sun.xml.writer.template',
87 => 'application/vnd.symbian.install',
88 => 'application/vnd.visio',
89 => 'application/vnd.wap.wbxml',
90 => 'application/vnd.wap.wmlc',
91 => 'application/vnd.wap.wmlscriptc',
92 => 'application/wordperfect',
93 => 'application/wordperfect5.1',
94 => 'application/x-123',
95 => 'application/x-7z-compressed',
96 => 'application/x-abiword',
97 => 'application/x-apple-diskimage',
98 => 'application/x-bcpio',
99 => 'application/x-bittorrent',
100 => 'application/x-cab',
101 => 'application/x-cbr',
102 => 'application/x-cbz',
103 => 'application/x-cdf',
104 => 'application/x-cdlink',
105 => 'application/x-chess-pgn',
106 => 'application/x-cpio',
107 => 'application/x-debian-package',
108 => 'application/x-director',
109 => 'application/x-dms',
110 => 'application/x-doom',
111 => 'application/x-dvi',
112 => 'application/x-flac',
113 => 'application/x-font',
114 => 'application/x-freemind',
115 => 'application/x-futuresplash',
116 => 'application/x-gnumeric',
117 => 'application/x-go-sgf',
118 => 'application/x-graphing-calculator',
119 => 'application/x-gtar',
120 => 'application/x-hdf',
121 => 'application/x-httpd-eruby',
122 => 'application/x-httpd-php',
123 => 'application/x-httpd-php-source',
124 => 'application/x-httpd-php3',
125 => 'application/x-httpd-php3-preprocessed',
126 => 'application/x-httpd-php4',
127 => 'application/x-ica',
128 => 'application/x-internet-signup',
129 => 'application/x-iphone',
130 => 'application/x-iso9660-image',
131 => 'application/x-java-jnlp-file',
132 => 'application/x-javascript',
133 => 'application/x-jmol',
134 => 'application/x-kchart',
135 => 'application/x-killustrator',
136 => 'application/x-koan',
137 => 'application/x-kpresenter',
138 => 'application/x-kspread',
139 => 'application/x-kword',
140 => 'application/x-latex',
141 => 'application/x-lha',
142 => 'application/x-lyx',
143 => 'application/x-lzh',
144 => 'application/x-lzx',
145 => 'application/x-maker',
146 => 'application/x-mif',
351 => 'application/x-mobipocket-ebook',
352 => 'application/x-mobipocket-ebook',
147 => 'application/x-ms-wmd',
148 => 'application/x-ms-wmz',
149 => 'application/x-msdos-program',
150 => 'application/x-msi',
151 => 'application/x-netcdf',
152 => 'application/x-ns-proxy-autoconfig',
153 => 'application/x-nwc',
154 => 'application/x-object',
155 => 'application/x-oz-application',
156 => 'application/x-pkcs7-certreqresp',
157 => 'application/x-pkcs7-crl',
158 => 'application/x-python-code',
159 => 'application/x-quicktimeplayer',
160 => 'application/x-redhat-package-manager',
161 => 'application/x-shar',
162 => 'application/x-shockwave-flash',
163 => 'application/x-stuffit',
164 => 'application/x-sv4cpio',
165 => 'application/x-sv4crc',
166 => 'application/x-tar',
167 => 'application/x-tcl',
168 => 'application/x-tex-gf',
169 => 'application/x-tex-pk',
170 => 'application/x-texinfo',
171 => 'application/x-trash',
172 => 'application/x-troff',
173 => 'application/x-troff-man',
174 => 'application/x-troff-me',
175 => 'application/x-troff-ms',
176 => 'application/x-ustar',
177 => 'application/x-wais-source',
178 => 'application/x-wingz',
179 => 'application/x-x509-ca-cert',
180 => 'application/x-xcf',
181 => 'application/x-xfig',
182 => 'application/x-xpinstall',
183 => 'application/xhtml+xml',
184 => 'application/xml',
185 => 'application/zip',
186 => 'audio/basic',
187 => 'audio/midi',
346 => 'audio/mp4',
188 => 'audio/mpeg',
189 => 'audio/ogg',
190 => 'audio/prs.sid',
356 => 'audio/webm',
191 => 'audio/x-aiff',
192 => 'audio/x-gsm',
354 => 'audio/x-matroska',
193 => 'audio/x-mpegurl',
194 => 'audio/x-ms-wax',
195 => 'audio/x-ms-wma',
196 => 'audio/x-pn-realaudio',
197 => 'audio/x-realaudio',
198 => 'audio/x-scpls',
199 => 'audio/x-sd2',
200 => 'audio/x-wav',
201 => 'chemical/x-alchemy',
202 => 'chemical/x-cache',
203 => 'chemical/x-cache-csf',
204 => 'chemical/x-cactvs-binary',
205 => 'chemical/x-cdx',
206 => 'chemical/x-cerius',
207 => 'chemical/x-chem3d',
208 => 'chemical/x-chemdraw',
209 => 'chemical/x-cif',
210 => 'chemical/x-cmdf',
211 => 'chemical/x-cml',
212 => 'chemical/x-compass',
213 => 'chemical/x-crossfire',
214 => 'chemical/x-csml',
215 => 'chemical/x-ctx',
216 => 'chemical/x-cxf',
217 => 'chemical/x-embl-dl-nucleotide',
218 => 'chemical/x-galactic-spc',
219 => 'chemical/x-gamess-input',
220 => 'chemical/x-gaussian-checkpoint',
221 => 'chemical/x-gaussian-cube',
222 => 'chemical/x-gaussian-input',
223 => 'chemical/x-gaussian-log',
224 => 'chemical/x-gcg8-sequence',
225 => 'chemical/x-genbank',
226 => 'chemical/x-hin',
227 => 'chemical/x-isostar',
228 => 'chemical/x-jcamp-dx',
229 => 'chemical/x-kinemage',
230 => 'chemical/x-macmolecule',
231 => 'chemical/x-macromodel-input',
232 => 'chemical/x-mdl-molfile',
233 => 'chemical/x-mdl-rdfile',
234 => 'chemical/x-mdl-rxnfile',
235 => 'chemical/x-mdl-sdfile',
236 => 'chemical/x-mdl-tgf',
237 => 'chemical/x-mmcif',
238 => 'chemical/x-mol2',
239 => 'chemical/x-molconn-Z',
240 => 'chemical/x-mopac-graph',
241 => 'chemical/x-mopac-input',
242 => 'chemical/x-mopac-out',
243 => 'chemical/x-mopac-vib',
244 => 'chemical/x-ncbi-asn1-ascii',
245 => 'chemical/x-ncbi-asn1-binary',
246 => 'chemical/x-ncbi-asn1-spec',
247 => 'chemical/x-pdb',
248 => 'chemical/x-rosdal',
249 => 'chemical/x-swissprot',
250 => 'chemical/x-vamas-iso14976',
251 => 'chemical/x-vmd',
252 => 'chemical/x-xtel',
253 => 'chemical/x-xyz',
254 => 'image/gif',
255 => 'image/ief',
256 => 'image/jpeg',
257 => 'image/pcx',
258 => 'image/png',
259 => 'image/svg+xml',
260 => 'image/tiff',
261 => 'image/vnd.djvu',
262 => 'image/vnd.microsoft.icon',
263 => 'image/vnd.wap.wbmp',
355 => 'image/webp',
264 => 'image/x-cmu-raster',
265 => 'image/x-coreldraw',
266 => 'image/x-coreldrawpattern',
267 => 'image/x-coreldrawtemplate',
268 => 'image/x-corelphotopaint',
269 => 'image/x-jg',
270 => 'image/x-jng',
271 => 'image/x-ms-bmp',
272 => 'image/x-photoshop',
273 => 'image/x-portable-anymap',
274 => 'image/x-portable-bitmap',
275 => 'image/x-portable-graymap',
276 => 'image/x-portable-pixmap',
277 => 'image/x-rgb',
278 => 'image/x-xbitmap',
279 => 'image/x-xpixmap',
280 => 'image/x-xwindowdump',
281 => 'message/rfc822',
282 => 'model/iges',
283 => 'model/mesh',
284 => 'model/vrml',
285 => 'text/calendar',
286 => 'text/css',
287 => 'text/csv',
288 => 'text/h323',
289 => 'text/html',
290 => 'text/iuls',
291 => 'text/mathml',
292 => 'text/plain',
293 => 'text/richtext',
294 => 'text/scriptlet',
295 => 'text/tab-separated-values',
296 => 'text/texmacs',
297 => 'text/vnd.sun.j2me.app-descriptor',
298 => 'text/vnd.wap.wml',
299 => 'text/vnd.wap.wmlscript',
358 => 'text/vtt',
300 => 'text/x-bibtex',
301 => 'text/x-boo',
302 => 'text/x-c++hdr',
303 => 'text/x-c++src',
304 => 'text/x-chdr',
305 => 'text/x-component',
306 => 'text/x-csh',
307 => 'text/x-csrc',
308 => 'text/x-diff',
309 => 'text/x-dsrc',
310 => 'text/x-haskell',
311 => 'text/x-java',
312 => 'text/x-literate-haskell',
313 => 'text/x-moc',
314 => 'text/x-pascal',
315 => 'text/x-pcs-gcd',
316 => 'text/x-perl',
317 => 'text/x-python',
318 => 'text/x-setext',
319 => 'text/x-sh',
320 => 'text/x-tcl',
321 => 'text/x-tex',
322 => 'text/x-vcalendar',
323 => 'text/x-vcard',
324 => 'video/3gpp',
325 => 'video/dl',
326 => 'video/dv',
327 => 'video/fli',
328 => 'video/gl',
329 => 'video/mp4',
330 => 'video/mpeg',
331 => 'video/ogg',
332 => 'video/quicktime',
333 => 'video/vnd.mpegurl',
357 => 'video/webm',
347 => 'video/x-flv',
334 => 'video/x-la-asf',
348 => 'video/x-m4v',
353 => 'video/x-matroska',
335 => 'video/x-mng',
336 => 'video/x-ms-asf',
337 => 'video/x-ms-wm',
338 => 'video/x-ms-wmv',
339 => 'video/x-ms-wmx',
340 => 'video/x-ms-wvx',
341 => 'video/x-msvideo',
342 => 'video/x-sgi-movie',
343 => 'x-conference/x-cooltalk',
344 => 'x-epoc/x-sisx-app',
345 => 'x-world/x-vrml',
),
// Extensions added to this list MUST be lower-case.
'extensions' => array(
'ez' => 0,
'atom' => 1,
'atomcat' => 2,
'atomsrv' => 3,
'cap' => 4,
'pcap' => 4,
'cu' => 5,
'tsp' => 6,
'hta' => 7,
'jar' => 8,
'ser' => 9,
'class' => 10,
'hqx' => 11,
'nb' => 12,
'mdb' => 13,
'dot' => 14,
'doc' => 14,
'bin' => 15,
'oda' => 16,
'ogx' => 17,
'pdf' => 18,
'key' => 19,
'pgp' => 20,
'prf' => 21,
'eps' => 22,
'ai' => 22,
'ps' => 22,
'rar' => 23,
'rdf' => 24,
'rss' => 25,
'rtf' => 26,
'smi' => 27,
'smil' => 27,
'cdy' => 28,
'kml' => 29,
'kmz' => 30,
'xul' => 31,
'xlb' => 32,
'xlt' => 32,
'xls' => 32,
'xlam' => 33,
'xlsb' => 34,
'xlsm' => 35,
'xltm' => 36,
'cat' => 37,
'stl' => 38,
'pps' => 39,
'ppt' => 39,
'ppam' => 40,
'pptm' => 41,
'ppsm' => 42,
'potm' => 43,
'docm' => 44,
'dotm' => 45,
'xps' => 46,
'odc' => 47,
'odb' => 48,
'odf' => 49,
'odg' => 50,
'otg' => 51,
'odi' => 52,
'odp' => 53,
'otp' => 54,
'ods' => 55,
'ots' => 56,
'odt' => 57,
'odm' => 58,
'ott' => 59,
'oth' => 60,
'pptx' => 61,
'ppsx' => 62,
'potx' => 63,
'xlsx' => 64,
'xltx' => 65,
'docx' => 66,
'dotx' => 67,
'cod' => 68,
'mmf' => 69,
'sdc' => 70,
'sds' => 71,
'sda' => 72,
'sdd' => 73,
'sdw' => 75,
'sgl' => 76,
'sxc' => 77,
'stc' => 78,
'sxd' => 79,
'std' => 80,
'sxi' => 81,
'sti' => 82,
'sxm' => 83,
'sxw' => 84,
'sxg' => 85,
'stw' => 86,
'sis' => 87,
'vsd' => 88,
'wbxml' => 89,
'wmlc' => 90,
'wmlsc' => 91,
'wpd' => 92,
'wp5' => 93,
'wk' => 94,
'7z' => 95,
'abw' => 96,
'dmg' => 97,
'bcpio' => 98,
'torrent' => 99,
'cab' => 100,
'cbr' => 101,
'cbz' => 102,
'cdf' => 103,
'vcd' => 104,
'pgn' => 105,
'cpio' => 106,
'udeb' => 107,
'deb' => 107,
'dir' => 108,
'dxr' => 108,
'dcr' => 108,
'dms' => 109,
'wad' => 110,
'dvi' => 111,
'flac' => 112,
'pfa' => 113,
'pfb' => 113,
'pcf' => 113,
'gsf' => 113,
'pcf.z' => 113,
'mm' => 114,
'spl' => 115,
'gnumeric' => 116,
'sgf' => 117,
'gcf' => 118,
'taz' => 119,
'gtar' => 119,
'tgz' => 119,
'hdf' => 120,
'rhtml' => 121,
'phtml' => 122,
'pht' => 122,
'php' => 122,
'phps' => 123,
'php3' => 124,
'php3p' => 125,
'php4' => 126,
'ica' => 127,
'ins' => 128,
'isp' => 128,
'iii' => 129,
'iso' => 130,
'jnlp' => 131,
'js' => 132,
'jmz' => 133,
'chrt' => 134,
'kil' => 135,
'skp' => 136,
'skd' => 136,
'skm' => 136,
'skt' => 136,
'kpr' => 137,
'kpt' => 137,
'ksp' => 138,
'kwd' => 139,
'kwt' => 139,
'latex' => 140,
'lha' => 141,
'lyx' => 142,
'lzh' => 143,
'lzx' => 144,
'maker' => 145,
'frm' => 145,
'frame' => 145,
'fm' => 145,
'book' => 145,
'fb' => 145,
'fbdoc' => 145,
'mif' => 146,
'wmd' => 147,
'wmz' => 148,
'dll' => 149,
'bat' => 149,
'exe' => 149,
'com' => 149,
'msi' => 150,
'nc' => 151,
'pac' => 152,
'nwc' => 153,
'o' => 154,
'oza' => 155,
'p7r' => 156,
'crl' => 157,
'pyo' => 158,
'pyc' => 158,
'qtl' => 159,
'rpm' => 160,
'shar' => 161,
'swf' => 162,
'swfl' => 162,
'sitx' => 163,
'sit' => 163,
'sv4cpio' => 164,
'sv4crc' => 165,
'tar' => 166,
'gf' => 168,
'pk' => 169,
'texi' => 170,
'texinfo' => 170,
'sik' => 171,
'~' => 171,
'bak' => 171,
'%' => 171,
'old' => 171,
't' => 172,
'roff' => 172,
'tr' => 172,
'man' => 173,
'me' => 174,
'ms' => 175,
'ustar' => 176,
'src' => 177,
'wz' => 178,
'crt' => 179,
'xcf' => 180,
'fig' => 181,
'xpi' => 182,
'xht' => 183,
'xhtml' => 183,
'xml' => 184,
'xsl' => 184,
'zip' => 185,
'au' => 186,
'snd' => 186,
'mid' => 187,
'midi' => 187,
'kar' => 187,
'mpega' => 188,
'mpga' => 188,
'm4a' => 188,
'mp3' => 188,
'mp2' => 188,
'ogg' => 189,
'oga' => 189,
'spx' => 189,
'sid' => 190,
'aif' => 191,
'aiff' => 191,
'aifc' => 191,
'gsm' => 192,
'm3u' => 193,
'wax' => 194,
'wma' => 195,
'rm' => 196,
'ram' => 196,
'ra' => 197,
'pls' => 198,
'sd2' => 199,
'wav' => 200,
'alc' => 201,
'cac' => 202,
'cache' => 202,
'csf' => 203,
'cascii' => 204,
'cbin' => 204,
'ctab' => 204,
'cdx' => 205,
'cer' => 206,
'c3d' => 207,
'chm' => 208,
'cif' => 209,
'cmdf' => 210,
'cml' => 211,
'cpa' => 212,
'bsd' => 213,
'csml' => 214,
'csm' => 214,
'ctx' => 215,
'cxf' => 216,
'cef' => 216,
'emb' => 217,
'embl' => 217,
'spc' => 218,
'gam' => 219,
'inp' => 219,
'gamin' => 219,
'fchk' => 220,
'fch' => 220,
'cub' => 221,
'gau' => 222,
'gjf' => 222,
'gjc' => 222,
'gal' => 223,
'gcg' => 224,
'gen' => 225,
'hin' => 226,
'istr' => 227,
'ist' => 227,
'dx' => 228,
'jdx' => 228,
'kin' => 229,
'mcm' => 230,
'mmd' => 231,
'mmod' => 231,
'mol' => 232,
'rd' => 233,
'rxn' => 234,
'sdf' => 235,
'sd' => 235,
'tgf' => 236,
'mcif' => 237,
'mol2' => 238,
'b' => 239,
'gpt' => 240,
'mopcrt' => 241,
'zmt' => 241,
'mpc' => 241,
'dat' => 241,
'mop' => 241,
'moo' => 242,
'mvb' => 243,
'prt' => 244,
'aso' => 245,
'val' => 245,
'asn' => 246,
'ent' => 247,
'pdb' => 247,
'ros' => 248,
'sw' => 249,
'vms' => 250,
'vmd' => 251,
'xtel' => 252,
'xyz' => 253,
'gif' => 254,
'ief' => 255,
'jpeg' => 256,
'jpe' => 256,
'jpg' => 256,
'pcx' => 257,
'png' => 258,
'svgz' => 259,
'svg' => 259,
'tif' => 260,
'tiff' => 260,
'djvu' => 261,
'djv' => 261,
'ico' => 262,
'wbmp' => 263,
'ras' => 264,
'cdr' => 265,
'pat' => 266,
'cdt' => 267,
'cpt' => 268,
'art' => 269,
'jng' => 270,
'bmp' => 271,
'psd' => 272,
'pnm' => 273,
'pbm' => 274,
'pgm' => 275,
'ppm' => 276,
'rgb' => 277,
'xbm' => 278,
'xpm' => 279,
'xwd' => 280,
'eml' => 281,
'igs' => 282,
'iges' => 282,
'silo' => 283,
'msh' => 283,
'mesh' => 283,
'icz' => 285,
'ics' => 285,
'css' => 286,
'csv' => 287,
'323' => 288,
'html' => 289,
'htm' => 289,
'shtml' => 289,
'uls' => 290,
'mml' => 291,
'txt' => 292,
'pot' => 292,
'text' => 292,
'asc' => 292,
'rtx' => 293,
'wsc' => 294,
'sct' => 294,
'tsv' => 295,
'ts' => 296,
'tm' => 296,
'jad' => 297,
'wml' => 298,
'wmls' => 299,
'bib' => 300,
'boo' => 301,
'hpp' => 302,
'hh' => 302,
'h++' => 302,
'hxx' => 302,
'cxx' => 303,
'cc' => 303,
'cpp' => 303,
'c++' => 303,
'h' => 304,
'htc' => 305,
'csh' => 306,
'c' => 307,
'patch' => 308,
'diff' => 308,
'd' => 309,
'hs' => 310,
'java' => 311,
'lhs' => 312,
'moc' => 313,
'pas' => 314,
'p' => 314,
'gcd' => 315,
'pm' => 316,
'pl' => 316,
'py' => 317,
'etx' => 318,
'sh' => 319,
'tk' => 320,
'tcl' => 320,
'cls' => 321,
'ltx' => 321,
'sty' => 321,
'tex' => 321,
'vcs' => 322,
'vcf' => 323,
'3gp' => 324,
'dl' => 325,
'dif' => 326,
'dv' => 326,
'fli' => 327,
'gl' => 328,
'mp4' => 329,
'f4v' => 329,
'f4p' => 329,
'mpe' => 330,
'mpeg' => 330,
'mpg' => 330,
'ogv' => 331,
'qt' => 332,
'mov' => 332,
'mxu' => 333,
'lsf' => 334,
'lsx' => 334,
'mng' => 335,
'asx' => 336,
'asf' => 336,
'wm' => 337,
'wmv' => 338,
'wmx' => 339,
'wvx' => 340,
'avi' => 341,
'movie' => 342,
'ice' => 343,
'sisx' => 344,
'wrl' => 345,
'vrm' => 345,
'vrml' => 345,
'f4a' => 346,
'f4b' => 346,
'flv' => 347,
'm4v' => 348,
'azw' => 349,
'epub' => 350,
'mobi' => 351,
'prc' => 352,
'mkv' => 353,
'mka' => 354,
'webp' => 355,
'weba' => 356,
'webm' => 357,
'vtt' => 358,
),
);
/**
* The MIME types mapping array after going through the module handler.
*
* @var array
*/
protected $mapping;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new ExtensionMimeTypeGuesser.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public function guess($path) {
if ($this->mapping === NULL) {
$mapping = $this->defaultMapping;
// Allow modules to alter the default mapping.
$this->moduleHandler->alter('file_mimetype_mapping', $mapping);
$this->mapping = $mapping;
}
$extension = '';
$file_parts = explode('.', drupal_basename($path));
// Remove the first part: a full filename should not match an extension.
array_shift($file_parts);
// Iterate over the file parts, trying to find a match.
// For my.awesome.image.jpeg, we try:
// - jpeg
// - image.jpeg, and
// - awesome.image.jpeg
while ($additional_part = array_pop($file_parts)) {
$extension = strtolower($additional_part . ($extension ? '.' . $extension : ''));
if (isset($this->mapping['extensions'][$extension])) {
return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
}
}
return 'application/octet-stream';
}
/**
* Sets the mimetypes/extension mapping to use when guessing mimetype.
*
* @param array|null $mapping
* Passing a NULL mapping will cause guess() to use self::$defaultMapping.
*/
public function setMapping(array $mapping = NULL) {
$this->mapping = $mapping;
}
}

View file

@ -0,0 +1,107 @@
<?php
/**
* @file
* Contains \Drupal\Core\File\MimeType\MimeTypeGuesser.
*/
namespace Drupal\Core\File\MimeType;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser as SymfonyMimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
/**
* Defines a MIME type guesser that also supports stream wrapper paths.
*/
class MimeTypeGuesser implements MimeTypeGuesserInterface {
/**
* An array of arrays of registered guessers keyed by priority.
*
* @var array
*/
protected $guessers = array();
/**
* Holds the array of guessers sorted by priority.
*
* If this is NULL a rebuild will be triggered.
*
* @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface[]
*
* @see \Drupal\Core\File\MimeType\MimeTypeGuesser::addGuesser()
* @see \Drupal\Core\File\MimeType\MimeTypeGuesser::sortGuessers()
*/
protected $sortedGuessers = NULL;
/**
* {@inheritdoc}
*/
public function guess($path) {
if ($wrapper = file_stream_wrapper_get_instance_by_uri($path)) {
// Get the real path from the stream wrapper.
$path = $wrapper->realpath();
}
if ($this->sortedGuessers === NULL) {
// Sort is not triggered yet.
$this->sortedGuessers = $this->sortGuessers();
}
foreach ($this->sortedGuessers as $guesser) {
$mime_type = $guesser->guess($path);
if ($mime_type !== NULL) {
return $mime_type;
}
}
}
/**
* Appends a MIME type guesser to the guessers chain.
*
* @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $guesser
* The guesser to be appended.
* @param int $priority
* The priority of the guesser being added.
*
* @return $this
*/
public function addGuesser(MimeTypeGuesserInterface $guesser, $priority = 0) {
$this->guessers[$priority][] = $guesser;
// Mark sorted guessers for rebuild.
$this->sortedGuessers = NULL;
return $this;
}
/**
* Sorts guessers according to priority.
*
* @return \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface[]
* A sorted array of MIME type guesser objects.
*/
protected function sortGuessers() {
$sorted = array();
krsort($this->guessers);
foreach ($this->guessers as $guesser) {
$sorted = array_merge($sorted, $guesser);
}
return $sorted;
}
/**
* A helper function to register with Symfony's singleton mime type guesser.
*
* Symfony's default mimetype guessers have dependencies on PHP's fileinfo
* extension or being able to run the system command file. Drupal's guesser
* does not have these dependencies.
*
* @see \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
*/
public static function registerWithSymfonyGuesser(ContainerInterface $container) {
$singleton = SymfonyMimeTypeGuesser::getInstance();
$singleton->register($container->get('file.mime_type.guesser'));
}
}

View file

@ -0,0 +1,201 @@
<?php
/**
* @file
* Hooks related to the File management system.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Control access to private file downloads and specify HTTP headers.
*
* This hook allows modules to enforce permissions on file downloads whenever
* Drupal is handling file download, as opposed to the web server bypassing
* Drupal and returning the file from a public directory. Modules can also
* provide headers to specify information like the file's name or MIME type.
*
* @param $uri
* The URI of the file.
* @return
* If the user does not have permission to access the file, return -1. If the
* user has permission, return an array with the appropriate headers. If the
* file is not controlled by the current module, the return value should be
* NULL.
*
* @see file_download()
*/
function hook_file_download($uri) {
// Check to see if this is a config download.
$scheme = file_uri_scheme($uri);
$target = file_uri_target($uri);
if ($scheme == 'temporary' && $target == 'config.tar.gz') {
return array(
'Content-disposition' => 'attachment; filename="config.tar.gz"',
);
}
}
/**
* Alter the URL to a file.
*
* This hook is called from file_create_url(), and is called fairly
* frequently (10+ times per page), depending on how many files there are in a
* given page.
* If CSS and JS aggregation are disabled, this can become very frequently
* (50+ times per page) so performance is critical.
*
* This function should alter the URI, if it wants to rewrite the file URL.
*
* @param $uri
* The URI to a file for which we need an external URL, or the path to a
* shipped file.
*/
function hook_file_url_alter(&$uri) {
$user = \Drupal::currentUser();
// User 1 will always see the local file in this example.
if ($user->id() == 1) {
return;
}
$cdn1 = 'http://cdn1.example.com';
$cdn2 = 'http://cdn2.example.com';
$cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');
// Most CDNs don't support private file transfers without a lot of hassle,
// so don't support this in the common case.
$schemes = array('public');
$scheme = file_uri_scheme($uri);
// Only serve shipped files and public created files from the CDN.
if (!$scheme || in_array($scheme, $schemes)) {
// Shipped files.
if (!$scheme) {
$path = $uri;
}
// Public created files.
else {
$wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
$path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
}
// Clean up Windows paths.
$path = str_replace('\\', '/', $path);
// Serve files with one of the CDN extensions from CDN 1, all others from
// CDN 2.
$pathinfo = pathinfo($path);
if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], $cdn_extensions)) {
$uri = $cdn1 . '/' . $path;
}
else {
$uri = $cdn2 . '/' . $path;
}
}
}
/**
* Alter MIME type mappings used to determine MIME type from a file extension.
*
* Invoked by \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess(). It
* is used to allow modules to add to or modify the default mapping from
* \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::$defaultMapping.
*
* @param $mapping
* An array of mimetypes correlated to the extensions that relate to them.
* The array has 'mimetypes' and 'extensions' elements, each of which is an
* array.
*
* @see \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess()
* @see \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::$defaultMapping
*/
function hook_file_mimetype_mapping_alter(&$mapping) {
// Add new MIME type 'drupal/info'.
$mapping['mimetypes']['example_info'] = 'drupal/info';
// Add new extension '.info.yml' and map it to the 'drupal/info' MIME type.
$mapping['extensions']['info'] = 'example_info';
// Override existing extension mapping for '.ogg' files.
$mapping['extensions']['ogg'] = 189;
}
/**
* Alter archiver information declared by other modules.
*
* See hook_archiver_info() for a description of archivers and the archiver
* information structure.
*
* @param $info
* Archiver information to alter (return values from hook_archiver_info()).
*/
function hook_archiver_info_alter(&$info) {
$info['tar']['extensions'][] = 'tgz';
}
/**
* Register information about FileTransfer classes provided by a module.
*
* The FileTransfer class allows transferring files over a specific type of
* connection. Core provides classes for FTP and SSH. Contributed modules are
* free to extend the FileTransfer base class to add other connection types,
* and if these classes are registered via hook_filetransfer_info(), those
* connection types will be available to site administrators using the Update
* manager when they are redirected to the authorize.php script to authorize
* the file operations.
*
* @return array
* Nested array of information about FileTransfer classes. Each key is a
* FileTransfer type (not human readable, used for form elements and
* variable names, etc), and the values are subarrays that define properties
* of that type. The keys in each subarray are:
* - 'title': Required. The human-readable name of the connection type.
* - 'class': Required. The name of the FileTransfer class. The constructor
* will always be passed the full path to the root of the site that should
* be used to restrict where file transfer operations can occur (the $jail)
* and an array of settings values returned by the settings form.
* - 'file': Required. The include file containing the FileTransfer class.
* This should be a separate .inc file, not just the .module file, so that
* the minimum possible code is loaded when authorize.php is running.
* - 'file path': Optional. The directory (relative to the Drupal root)
* where the include file lives. If not defined, defaults to the base
* directory of the module implementing the hook.
* - 'weight': Optional. Integer weight used for sorting connection types on
* the authorize.php form.
*
* @see \Drupal\Core\FileTransfer\FileTransfer
* @see authorize.php
* @see hook_filetransfer_info_alter()
* @see drupal_get_filetransfer_info()
*/
function hook_filetransfer_info() {
$info['sftp'] = array(
'title' => t('SFTP (Secure FTP)'),
'class' => 'Drupal\Core\FileTransfer\SFTP',
'weight' => 10,
);
return $info;
}
/**
* Alter the FileTransfer class registry.
*
* @param array $filetransfer_info
* Reference to a nested array containing information about the FileTransfer
* class registry.
*
* @see hook_filetransfer_info()
*/
function hook_filetransfer_info_alter(&$filetransfer_info) {
// Remove the FTP option entirely.
unset($filetransfer_info['ftp']);
// Make sure the SSH option is listed first.
$filetransfer_info['ssh']['weight'] = -10;
}
/**
* @} End of "addtogroup hooks".
*/