Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / URIScheme / ftp.php
blob5555ef33a179ea60395331e6666914ed1975ef17
1 <?php
3 require_once 'HTMLPurifier/URIScheme.php';
5 /**
6 * Validates ftp (File Transfer Protocol) URIs as defined by generic RFC 1738.
7 */
8 class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme {
10 var $default_port = 21;
11 var $browsable = true; // usually
12 var $hierarchical = true;
14 function validate(&$uri, $config, &$context) {
15 parent::validate($uri, $config, $context);
16 $uri->query = null;
18 // typecode check
19 $semicolon_pos = strrpos($uri->path, ';'); // reverse
20 if ($semicolon_pos !== false) {
21 $type = substr($uri->path, $semicolon_pos + 1); // no semicolon
22 $uri->path = substr($uri->path, 0, $semicolon_pos);
23 $type_ret = '';
24 if (strpos($type, '=') !== false) {
25 // figure out whether or not the declaration is correct
26 list($key, $typecode) = explode('=', $type, 2);
27 if ($key !== 'type') {
28 // invalid key, tack it back on encoded
29 $uri->path .= '%3B' . $type;
30 } elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') {
31 $type_ret = ";type=$typecode";
33 } else {
34 $uri->path .= '%3B' . $type;
36 $uri->path = str_replace(';', '%3B', $uri->path);
37 $uri->path .= $type_ret;
40 return true;