Advertisement
Guest User

unzend.com_338

a guest
Jan 16th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.60 KB | None | 0 0
  1. <?php
  2. // ionCube version 9 Decoder unzend.com - Email: unzend@gmail.com
  3. // http://www.unzend.com
  4. /**
  5.  * CHtmlPurifier class file.
  6.  *
  7.  * @author Qiang Xue <qiang.xue@gmail.com>
  8.  * @link http://www.yiiframework.com/
  9.  * @copyright 2008-2013 Yii Software LLC
  10.  * @license http://www.yiiframework.com/license/
  11.  */
  12.  
  13. if(!class_exists('HTMLPurifier_Bootstrap',false))
  14. {
  15.     require_once(Yii::getPathOfAlias('system.vendors.htmlpurifier').DIRECTORY_SEPARATOR.'HTMLPurifier.standalone.php');
  16.     HTMLPurifier_Bootstrap::registerAutoload();
  17. }
  18.  
  19. /**
  20.  * CHtmlPurifier is wrapper of {@link http://htmlpurifier.org HTML Purifier}.
  21.  *
  22.  * CHtmlPurifier removes all malicious code (better known as XSS) with a thoroughly audited,
  23.  * secure yet permissive whitelist. It will also make sure the resulting code
  24.  * is standard-compliant.
  25.  *
  26.  * CHtmlPurifier can be used as either a widget or a controller filter.
  27.  *
  28.  * Note: since HTML Purifier is a big package, its performance is not very good.
  29.  * You should consider either caching the purification result or purifying the user input
  30.  * before saving to database.
  31.  *
  32.  * Usage as a class:
  33.  * <pre>
  34.  * $p = new CHtmlPurifier();
  35.  * $p->options = array('URI.AllowedSchemes'=>array(
  36.  *   'http' => true,
  37.  *   'https' => true,
  38.  * ));
  39.  * $text = $p->purify($text);
  40.  * </pre>
  41.  *
  42.  * Usage as validation rule:
  43.  * <pre>
  44.  * array('text','filter','filter'=>array($obj=new CHtmlPurifier(),'purify')),
  45.  * </pre>
  46.  *
  47.  * @author Qiang Xue <qiang.xue@gmail.com>
  48.  * @package system.web.widgets
  49.  * @since 1.0
  50.  */
  51. class CHtmlPurifier extends COutputProcessor
  52. {
  53.     /**
  54.      * @var object the HTML Purifier instance.
  55.      */
  56.     private $_purifier;
  57.     /**
  58.      * @var mixed the options to be passed to HTML Purifier instance.
  59.      * This can be a HTMLPurifier_Config object,  an array of directives (Namespace.Directive => Value)
  60.      * or the filename of an ini file.
  61.      * @see http://htmlpurifier.org/live/configdoc/plain.html
  62.      */
  63.     private $_options=null;
  64.    
  65.     /**
  66.      * Processes the captured output.
  67.      * This method purifies the output using {@link http://htmlpurifier.org HTML Purifier}.
  68.      * @param string $output the captured output to be processed
  69.      */
  70.     public function processOutput($output)
  71.     {
  72.         $output=$this->purify($output);
  73.         parent::processOutput($output);
  74.     }
  75.    
  76.     /**
  77.      * Purifies the HTML content by removing malicious code.
  78.      * @param mixed $content the content to be purified.
  79.      * @return mixed the purified content
  80.      */
  81.     public function purify($content)
  82.     {
  83.         if(is_array($content))
  84.             $content=array_map(array($this,'purify'),$content);
  85.         else
  86.             $content=$this->getPurifier()->purify($content);
  87.         return $content;
  88.     }
  89.    
  90.     /**
  91.      * Set the options for HTML Purifier and create a new HTML Purifier instance based on these options.
  92.      * @param mixed $options the options for HTML Purifier
  93.      * @return CHtmlPurifier
  94.      */
  95.     public function setOptions($options)
  96.     {
  97.         $this->_options=$options;
  98.         $this->createNewHtmlPurifierInstance();
  99.         return $this;
  100.     }
  101.    
  102.     /**
  103.      * Get the options for the HTML Purifier instance.
  104.      * @return mixed the HTML Purifier instance options
  105.      */
  106.     public function getOptions()
  107.     {
  108.         return $this->_options;
  109.     }
  110.    
  111.     /**
  112.      * Get the HTML Purifier instance or create a new one if it doesn't exist.
  113.      * @return HTMLPurifier
  114.      */
  115.     protected function getPurifier()
  116.     {
  117.         if($this->_purifier!==null)
  118.             return $this->_purifier;
  119.         return $this->createNewHtmlPurifierInstance();
  120.     }
  121.    
  122.     /**
  123.      * Create a new HTML Purifier instance.
  124.      * @return HTMLPurifier
  125.      */
  126.     protected function createNewHtmlPurifierInstance()
  127.     {
  128.         $this->_purifier=new HTMLPurifier($this->getOptions());
  129.         $this->_purifier->config->set('Cache.SerializerPath',Yii::app()->getRuntimePath());
  130.         return $this->_purifier;
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement