\n.*HTML text and image', '>Moodle Forum',
'Welcome to Moodle, '
- .'
!
',
'>Love Moodle', '>1\d1');
diff --git a/pluginfile.php b/pluginfile.php
index 3d6d542496e..24e6cda10e9 100644
--- a/pluginfile.php
+++ b/pluginfile.php
@@ -25,12 +25,16 @@
*/
// Disable moodle specific debug messages and any errors in output.
-define('NO_DEBUG_DISPLAY', true);
+if (!defined('NO_DEBUG_DISPLAY')) {
+ define('NO_DEBUG_DISPLAY', true);
+}
require_once('config.php');
require_once('lib/filelib.php');
-$relativepath = get_file_argument();
+if (empty($relativepath)) {
+ $relativepath = get_file_argument();
+}
$forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
$preview = optional_param('preview', null, PARAM_ALPHANUM);
// Offline means download the file from the repository and serve it, even if it was an external link.
diff --git a/tokenpluginfile.php b/tokenpluginfile.php
new file mode 100644
index 00000000000..156d4126f80
--- /dev/null
+++ b/tokenpluginfile.php
@@ -0,0 +1,44 @@
+.
+
+/**
+ * Entry point for token-based access to pluginfile.php.
+ *
+ * @package core
+ * @copyright 2018 Andrew Nicols
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+// Disable the use of sessions/cookies - we recreate $USER for every call.
+define('NO_MOODLE_COOKIES', true);
+
+// Disable debugging for this script.
+// It is typically used to display images.
+define('NO_DEBUG_DISPLAY', true);
+
+require_once('config.php');
+
+$relativepath = get_file_argument();
+$token = optional_param('token', '', PARAM_ALPHANUM);
+if (0 == strpos($relativepath, '/token/')) {
+ $relativepath = ltrim($relativepath, '/');
+ $pathparts = explode('/', $relativepath, 2);
+ $token = $pathparts[0];
+ $relativepath = "/{$pathparts[1]}";
+}
+
+require_user_key_login('core_files', null, $token);
+require_once('pluginfile.php');