File indexing completed on 2024-05-12 06:02:06

0001 <?php
0002 
0003 /**
0004  * Validates ftp (File Transfer Protocol) URIs as defined by generic RFC 1738.
0005  */
0006 class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme
0007 {
0008     /**
0009      * @type int
0010      */
0011     public $default_port = 21;
0012 
0013     /**
0014      * @type bool
0015      */
0016     public $browsable = true; // usually
0017 
0018     /**
0019      * @type bool
0020      */
0021     public $hierarchical = true;
0022 
0023     /**
0024      * @param HTMLPurifier_URI $uri
0025      * @param HTMLPurifier_Config $config
0026      * @param HTMLPurifier_Context $context
0027      * @return bool
0028      */
0029     public function doValidate(&$uri, $config, $context)
0030     {
0031         $uri->query = null;
0032 
0033         // typecode check
0034         $semicolon_pos = strrpos($uri->path, ';'); // reverse
0035         if ($semicolon_pos !== false) {
0036             $type = substr($uri->path, $semicolon_pos + 1); // no semicolon
0037             $uri->path = substr($uri->path, 0, $semicolon_pos);
0038             $type_ret = '';
0039             if (strpos($type, '=') !== false) {
0040                 // figure out whether or not the declaration is correct
0041                 list($key, $typecode) = explode('=', $type, 2);
0042                 if ($key !== 'type') {
0043                     // invalid key, tack it back on encoded
0044                     $uri->path .= '%3B' . $type;
0045                 } elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') {
0046                     $type_ret = ";type=$typecode";
0047                 }
0048             } else {
0049                 $uri->path .= '%3B' . $type;
0050             }
0051             $uri->path = str_replace(';', '%3B', $uri->path);
0052             $uri->path .= $type_ret;
0053         }
0054         return true;
0055     }
0056 }
0057 
0058 // vim: et sw=4 sts=4