summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-01-26 08:29:25 +0000
committerDries Buytaert <dries@buytaert.net>2010-01-26 08:29:25 +0000
commitd53f3e39d5da63f20a90f3a221da139b7afa7673 (patch)
tree3058e2d4cae41d4f6f0c1dd2f9484ace1565ac58 /includes
parent420c27c4892ab5a0a9009f0006786bd5e7c0a787 (diff)
downloadbrdo-d53f3e39d5da63f20a90f3a221da139b7afa7673.tar.gz
brdo-d53f3e39d5da63f20a90f3a221da139b7afa7673.tar.bz2
- Patch #685074 by pwolanin: some stream wrappers need to be hidden or read-only.
Diffstat (limited to 'includes')
-rw-r--r--includes/file.inc32
-rw-r--r--includes/stream_wrappers.inc59
2 files changed, 87 insertions, 4 deletions
diff --git a/includes/file.inc b/includes/file.inc
index 4423b2d6b..6395c6323 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -90,16 +90,24 @@ define('FILE_STATUS_PERMANENT', 1);
*
* A stream is referenced as "scheme://target".
*
+ * @param $filter
+ * Optionally filter out all types except these. Defaults to
+ * STREAM_WRAPPERS_ALL, which returns all registered stream wrappers.
+ *
* @return
* Returns the entire Drupal stream wrapper registry.
* @see hook_stream_wrappers()
* @see hook_stream_wrappers_alter()
*/
-function file_get_stream_wrappers() {
- $wrappers = &drupal_static(__FUNCTION__);
+function file_get_stream_wrappers($filter = STREAM_WRAPPERS_ALL) {
+ $wrappers_storage = &drupal_static(__FUNCTION__);
- if (!isset($wrappers)) {
+ if (!isset($wrappers_storage)) {
$wrappers = module_invoke_all('stream_wrappers');
+ foreach ($wrappers as $scheme => $info) {
+ // Add defaults.
+ $wrappers[$scheme] += array('type' => STREAM_WRAPPERS_NORMAL);
+ }
drupal_alter('stream_wrappers', $wrappers);
$existing = stream_get_wrappers();
foreach ($wrappers as $scheme => $info) {
@@ -115,9 +123,25 @@ function file_get_stream_wrappers() {
}
stream_wrapper_register($scheme, $info['class']);
}
+ // Pre-populate the static cache with the filters most typically used.
+ $wrappers_storage[STREAM_WRAPPERS_ALL][$scheme] = $wrappers[$scheme];
+ if (($info['type'] & STREAM_WRAPPERS_WRITE_VISIBLE) == STREAM_WRAPPERS_WRITE_VISIBLE) {
+ $wrappers_storage[STREAM_WRAPPERS_WRITE_VISIBLE][$scheme] = $wrappers[$scheme];
+ }
}
}
- return $wrappers;
+
+ if (!isset($wrappers_storage[$filter])) {
+ $wrappers_storage[$filter] = array();
+ foreach ($wrappers_storage[STREAM_WRAPPERS_ALL] as $scheme => $info) {
+ // Bit-wise filter.
+ if ($info['type'] & $filter == $filter) {
+ $wrappers_storage[$filter][$scheme] = $info;
+ }
+ }
+ }
+
+ return $wrappers_storage[$filter];
}
/**
diff --git a/includes/stream_wrappers.inc b/includes/stream_wrappers.inc
index 8ed5c8517..b4edb0933 100644
--- a/includes/stream_wrappers.inc
+++ b/includes/stream_wrappers.inc
@@ -21,6 +21,65 @@
*/
/**
+ * Stream wrapper bit flags that are the basis for composite types.
+ */
+
+/**
+ * Stream wrapper bit flag -- a filter that matches all wrappers.
+ */
+define ('STREAM_WRAPPERS_ALL', 0x0000);
+
+/**
+ * Stream wrapper bit flag -- refers to a local file system location.
+ */
+define ('STREAM_WRAPPERS_LOCAL', 0x0001);
+
+/**
+ * Stream wrapper bit flag -- refers to a remote filesystem location.
+ */
+define ('STREAM_WRAPPERS_REMOTE', 0x0002);
+
+/**
+ * Stream wrapper bit flag -- wrapper is readable (almost always true).
+ */
+define ('STREAM_WRAPPERS_READ', 0x0004);
+
+/**
+ * Stream wrapper bit flag -- wrapper is writeable.
+ */
+define ('STREAM_WRAPPERS_WRITE', 0x0008);
+
+/**
+ * Stream wrapper bit flag -- exposed in the UI and potentially web accessible.
+ */
+define ('STREAM_WRAPPERS_VISIBLE', 0x0010);
+
+/**
+ * Composite stream wrapper bit flags that are usually used as the types.
+ */
+
+/**
+ * Stream wrapper type flag -- not visible in the UI or accessible via web,
+ * but readable and writable. E.g. the temporary directory for uploads.
+ */
+define ('STREAM_WRAPPERS_HIDDEN', STREAM_WRAPPERS_READ | STREAM_WRAPPERS_WRITE);
+
+/**
+ * Stream wrapper type flag -- visible, readable and writeable.
+ */
+define ('STREAM_WRAPPERS_WRITE_VISIBLE', STREAM_WRAPPERS_READ | STREAM_WRAPPERS_WRITE | STREAM_WRAPPERS_VISIBLE);
+
+/**
+ * Stream wrapper type flag -- visible and read-only.
+ */
+define ('STREAM_WRAPPERS_READ_VISIBLE', STREAM_WRAPPERS_READ | STREAM_WRAPPERS_VISIBLE);
+
+/**
+ * Stream wrapper type flag -- visible, readable and writeable using local files.
+ */
+define ('STREAM_WRAPPERS_NORMAL', STREAM_WRAPPERS_LOCAL | STREAM_WRAPPERS_WRITE_VISIBLE);
+
+/**
* Generic PHP stream wrapper interface.
*
* @see http://www.php.net/manual/en/class.streamwrapper.php