Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/htmlpurifier/HTMLPurifier/URIFilter/Munge.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class HTMLPurifier_URIFilter_Munge extends HTMLPurifier_URIFilter
00004 {
00005     public $name = 'Munge';
00006     public $post = true;
00007     private $target, $parser, $doEmbed, $secretKey;
00008 
00009     protected $replace = array();
00010 
00011     public function prepare($config) {
00012         $this->target    = $config->get('URI.' . $this->name);
00013         $this->parser    = new HTMLPurifier_URIParser();
00014         $this->doEmbed   = $config->get('URI.MungeResources');
00015         $this->secretKey = $config->get('URI.MungeSecretKey');
00016         return true;
00017     }
00018     public function filter(&$uri, $config, $context) {
00019         if ($context->get('EmbeddedURI', true) && !$this->doEmbed) return true;
00020 
00021         $scheme_obj = $uri->getSchemeObj($config, $context);
00022         if (!$scheme_obj) return true; // ignore unknown schemes, maybe another postfilter did it
00023         if (is_null($uri->host) || empty($scheme_obj->browsable)) {
00024             return true;
00025         }
00026         // don't redirect if target host is our host
00027         if ($uri->host === $config->getDefinition('URI')->host) {
00028             return true;
00029         }
00030 
00031         $this->makeReplace($uri, $config, $context);
00032         $this->replace = array_map('rawurlencode', $this->replace);
00033 
00034         $new_uri = strtr($this->target, $this->replace);
00035         $new_uri = $this->parser->parse($new_uri);
00036         // don't redirect if the target host is the same as the
00037         // starting host
00038         if ($uri->host === $new_uri->host) return true;
00039         $uri = $new_uri; // overwrite
00040         return true;
00041     }
00042 
00043     protected function makeReplace($uri, $config, $context) {
00044         $string = $uri->toString();
00045         // always available
00046         $this->replace['%s'] = $string;
00047         $this->replace['%r'] = $context->get('EmbeddedURI', true);
00048         $token = $context->get('CurrentToken', true);
00049         $this->replace['%n'] = $token ? $token->name : null;
00050         $this->replace['%m'] = $context->get('CurrentAttr', true);
00051         $this->replace['%p'] = $context->get('CurrentCSSProperty', true);
00052         // not always available
00053         if ($this->secretKey) $this->replace['%t'] = sha1($this->secretKey . ':' . $string);
00054     }
00055 
00056 }
00057 
00058 // vim: et sw=4 sts=4
 All Data Structures Namespaces Files Functions Variables Enumerations