Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-29624 Media embedding system, part 0: Add get_path() to moodle_url

(It may not seem directly related, but this function is needed for the
media embedding system.
  • Loading branch information...
commit ffe4de973b36636c06fdf6a44a872d99de0856b9 1 parent e16e230
@sammarshallou sammarshallou authored
Showing with 32 additions and 0 deletions.
  1. +15 −0 lib/tests/weblib_test.php
  2. +17 −0 lib/weblib.php
View
15 lib/tests/weblib_test.php
@@ -112,6 +112,21 @@ function test_wikify_links() {
$this->assertEquals(wikify_links('this is a <a href="http://someaddress.com/query">link</a>'), 'this is a link [ http://someaddress.com/query ]');
}
+ /**
+ * Tests moodle_url::get_path().
+ */
+ public function test_moodle_url_get_path() {
+ $url = new moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
+ $this->assertEquals('/my/file/is/here.txt', $url->get_path());
+
+ $url = new moodle_url('http://www.example.org/');
+ $this->assertEquals('/', $url->get_path());
+
+ $url = new moodle_url('http://www.example.org/pluginfile.php/slash/arguments');
+ $this->assertEquals('/pluginfile.php/slash/arguments', $url->get_path());
+ $this->assertEquals('/pluginfile.php', $url->get_path(false));
+ }
+
function test_moodle_url_round_trip() {
$strurl = 'http://moodle.org/course/view.php?id=5';
$url = new moodle_url($strurl);
View
17 lib/weblib.php
@@ -754,6 +754,23 @@ public function out_as_local_url($escaped = true, array $overrideparams = null)
return str_replace($CFG->wwwroot, '', $url);
}
+
+ /**
+ * Returns the 'path' portion of a URL. For example, if the URL is
+ * http://www.example.org:447/my/file/is/here.txt?really=1 then this will
+ * return '/my/file/is/here.txt'.
+ *
+ * By default the path includes slash-arguments (for example,
+ * '/myfile.php/extra/arguments') so it is what you would expect from a
+ * URL path. If you don't want this behaviour, you can opt to exclude the
+ * slash arguments.
+ *
+ * @param bool $includeslashargument If true, includes slash arguments
+ * @return string Path of URL
+ */
+ public function get_path($includeslashargument = true) {
+ return $this->path . ($includeslashargument ? $this->slashargument : '');
+ }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.