CCFileBase
in package
Expand and canonicalize Common Cartridge course-local URLs in HTML.
At rest in the database, course-local URLs use the historical token concatenated onto a relative path with no slash after the token:
$IMS-CC-FILEBASE$pages/week2
$IMS-CC-FILEBASE$files/images/example.png
That is the Common Cartridge spelling, not LTI. The implementation
guide's examples are $TOKEN$images/icon.gif (no slash between the
closing $ and the path). The token is a flag for importers; the path
after it is relative to the resource base directory.
Tags
Table of Contents
Constants
- TOKEN : mixed = '$IMS-CC-FILEBASE$'
- Historical Common Cartridge file-base token.
- TOKEN_ALIASES : mixed = array('$IMS-CC-FILEBASE$', '$1EdTech-CC-FILEBAS...
- Token spellings recognized on input. The first entry is the storage form.
- URL_ATTRIBUTES : mixed = array('href', 'src', 'poster', 'action', 'forma...
- HTML attributes that carry a single URL.
Methods
- canonicalize() : string
- Convert current-course URLs (and token aliases) to $IMS-CC-FILEBASE$.
- courseBaseUrl() : string
- Build a course file-base URL from a request path prefix and site home.
- courseRemainder() : string|null
- Remainder after the course prefix, or null if the URL is not course-local.
- expand() : string
- Convert FILEBASE tokens and historical course-local URLs to the current course URL.
- rewriteUrl() : string
- collapseSlashRuns() : string
- Collapse duplicate slashes in a path. Does not touch a URL scheme.
- collapseUrlPathSlashes() : string
- Collapse duplicate slashes in the path of an absolute or path-absolute URL.
- containsFileBaseToken() : bool
- fragmentFromUrl() : string|null
- joinCourseUrl() : string
- normalizeRemainder() : string
- Remainder with no leading slash and no duplicate slashes in the path.
- pathHasDotDot() : bool
- portsCompatible() : bool
- prefixCandidates() : array<int, array{scheme: ?string, host: ?string, port: ?int, path: string}>
- Prefixes to try when matching a URL to the current course, longest first.
- queryFromUrl() : string|null
- remainderAfterPrefix() : string|null
- remainderFromToken() : string|null
- remainderStartsWithLocalPrefix() : bool
- rewriteHtml() : string
- rewriteSrcset() : string
- shouldSkipUrl() : bool
- splitUrl() : array{scheme: ?string, host: ?string, port: ?int, path: string, query: ?string, fragment: ?string, original: string}|null
- stripPathPrefix() : string|null
Constants
TOKEN
Historical Common Cartridge file-base token.
public
mixed
TOKEN
= '$IMS-CC-FILEBASE$'
Do not put a slash inside or after this string. Spec examples write
$IMS-CC-FILEBASE$images/icon.gif, not $IMS-CC-FILEBASE$/images/icon.gif.
A slash after the token is accepted on input and stripped.
Tags
TOKEN_ALIASES
Token spellings recognized on input. The first entry is the storage form.
public
mixed
TOKEN_ALIASES
= array('$IMS-CC-FILEBASE$', '$1EdTech-CC-FILEBASE$', '$IMS_CC_FILEBASE$')
URL_ATTRIBUTES
HTML attributes that carry a single URL.
public
mixed
URL_ATTRIBUTES
= array('href', 'src', 'poster', 'action', 'formaction', 'cite', 'data', 'data-oembed-url', 'longdesc', 'background')
Methods
canonicalize()
Convert current-course URLs (and token aliases) to $IMS-CC-FILEBASE$.
public
static canonicalize(string $html, string $courseBaseUrl[, array<string|int, string> $courseLocalPrefixes = array() ]) : string
..
Parameters
- $html : string
- $courseBaseUrl : string
- $courseLocalPrefixes : array<string|int, string> = array()
Return values
stringcourseBaseUrl()
Build a course file-base URL from a request path prefix and site home.
public
static courseBaseUrl(string $pathPrefix[, string|null $absoluteHome = null ]) : string
Parameters
- $pathPrefix : string
-
toolParent() value, e.g. '/courses/2' or '/py4e' or ''
- $absoluteHome : string|null = null
-
$CFG->apphome or $CFG->wwwroot
Return values
string —Course base with no trailing slash
courseRemainder()
Remainder after the course prefix, or null if the URL is not course-local.
public
static courseRemainder(string $url, string $courseBaseUrl[, array<string|int, string> $courseLocalPrefixes = array() ]) : string|null
Query string and fragment are kept on the remainder.
Parameters
- $url : string
- $courseBaseUrl : string
- $courseLocalPrefixes : array<string|int, string> = array()
Return values
string|nullexpand()
Convert FILEBASE tokens and historical course-local URLs to the current course URL.
public
static expand(string $html, string $courseBaseUrl[, array<string|int, string> $courseLocalPrefixes = array() ]) : string
Parameters
- $html : string
- $courseBaseUrl : string
- $courseLocalPrefixes : array<string|int, string> = array()
-
First path segments the caller treats as course-local (e.g.
pages,files). Empty means: rewrite any path under a non-empty course base, but not origin-only URLs.
Return values
stringrewriteUrl()
public
static rewriteUrl(string $url, string $courseBaseUrl, string $mode[, array<string|int, string> $courseLocalPrefixes = array() ]) : string
Parameters
- $url : string
- $courseBaseUrl : string
- $mode : string
- $courseLocalPrefixes : array<string|int, string> = array()
Return values
stringcollapseSlashRuns()
Collapse duplicate slashes in a path. Does not touch a URL scheme.
private
static collapseSlashRuns(string $path) : string
Parameters
- $path : string
Return values
stringcollapseUrlPathSlashes()
Collapse duplicate slashes in the path of an absolute or path-absolute URL.
private
static collapseUrlPathSlashes(string $url) : string
Parameters
- $url : string
Return values
stringcontainsFileBaseToken()
private
static containsFileBaseToken(string $html) : bool
Parameters
- $html : string
Return values
boolfragmentFromUrl()
private
static fragmentFromUrl(string $url, array<string|int, mixed> $parts) : string|null
Parameters
- $url : string
- $parts : array<string|int, mixed>
Return values
string|nulljoinCourseUrl()
private
static joinCourseUrl(string $courseBaseUrl, string $remainder) : string
Parameters
- $courseBaseUrl : string
- $remainder : string
Return values
stringnormalizeRemainder()
Remainder with no leading slash and no duplicate slashes in the path.
private
static normalizeRemainder(string $remainder) : string
Query string and fragment are left intact (so http:// in a query stays).
Parameters
- $remainder : string
Return values
stringpathHasDotDot()
private
static pathHasDotDot(string $remainder) : bool
Parameters
- $remainder : string
Return values
boolportsCompatible()
private
static portsCompatible(int|null $a, int|null $b, string|null $schemeA, string|null $schemeB) : bool
Parameters
- $a : int|null
- $b : int|null
- $schemeA : string|null
- $schemeB : string|null
Return values
boolprefixCandidates()
Prefixes to try when matching a URL to the current course, longest first.
private
static prefixCandidates(array<string|int, mixed> $baseParts) : array<int, array{scheme: ?string, host: ?string, port: ?int, path: string}>
Parameters
- $baseParts : array<string|int, mixed>
Return values
array<int, array{scheme: ?string, host: ?string, port: ?int, path: string}>queryFromUrl()
private
static queryFromUrl(string $url, array<string|int, mixed> $parts) : string|null
Parameters
- $url : string
- $parts : array<string|int, mixed>
Return values
string|nullremainderAfterPrefix()
private
static remainderAfterPrefix(string $url, array<string|int, mixed> $prefix) : string|null
Parameters
- $url : string
- $prefix : array<string|int, mixed>
Return values
string|nullremainderFromToken()
private
static remainderFromToken(string $url) : string|null
Parameters
- $url : string
Return values
string|null —Remainder after a FILEBASE token, or null
remainderStartsWithLocalPrefix()
private
static remainderStartsWithLocalPrefix(string $remainder, array<string|int, string> $courseLocalPrefixes) : bool
Parameters
- $remainder : string
- $courseLocalPrefixes : array<string|int, string>
Return values
boolrewriteHtml()
private
static rewriteHtml(string $html, string $courseBaseUrl, string $mode[, array<string|int, string> $courseLocalPrefixes = array() ]) : string
Parameters
- $html : string
- $courseBaseUrl : string
- $mode : string
-
expand|canonicalize
- $courseLocalPrefixes : array<string|int, string> = array()
Return values
stringrewriteSrcset()
private
static rewriteSrcset(string $value, string $courseBaseUrl, string $mode[, array<string|int, string> $courseLocalPrefixes = array() ]) : string
Parameters
- $value : string
- $courseBaseUrl : string
- $mode : string
- $courseLocalPrefixes : array<string|int, string> = array()
Return values
stringshouldSkipUrl()
private
static shouldSkipUrl(string $url) : bool
Parameters
- $url : string
Return values
boolsplitUrl()
private
static splitUrl(string $url) : array{scheme: ?string, host: ?string, port: ?int, path: string, query: ?string, fragment: ?string, original: string}|null
Parameters
- $url : string
Return values
array{scheme: ?string, host: ?string, port: ?int, path: string, query: ?string, fragment: ?string, original: string}|nullstripPathPrefix()
private
static stripPathPrefix(string $path, string $prefix) : string|null
Parameters
- $path : string
- $prefix : string
Return values
string|null —Path after prefix, no leading slash; null if not under prefix