Fix fatal error HTMLPurifier_Filter_AllowIframes #7922

1.10.x
Julio 10 years ago
parent cdbff1a580
commit eae9d76b23
  1. 4
      main/inc/lib/security.lib.php
  2. 14
      src/Chamilo/CoreBundle/Component/HTMLPurifier/Filter/AllowIframes.php

@ -23,6 +23,8 @@
* @author Yannick Warnier <ywarnier@beeznest.org> * @author Yannick Warnier <ywarnier@beeznest.org>
*/ */
use Chamilo\CoreBundle\Component\HTMLPurifier\Filter\AllowIframes;
/** /**
* Security class * Security class
* *
@ -338,7 +340,7 @@ class Security
$config->set('Core.RemoveProcessingInstructions', true); $config->set('Core.RemoveProcessingInstructions', true);
if (api_get_setting('enable_iframe_inclusion') == 'true') { if (api_get_setting('enable_iframe_inclusion') == 'true') {
$config->set('Filter.Custom', array(new HTMLPurifier_Filter_AllowIframes())); $config->set('Filter.Custom', array(new AllowIframes()));
} }
// Shows _target attribute in anchors // Shows _target attribute in anchors

@ -1,4 +1,12 @@
<?php <?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Component\HTMLPurifier\Filter;
use HTMLPurifier_Filter;
use HTMLPurifier_Config;
use HTMLPurifier_Context;
/** /**
* Class definition for HTMLPurifier that allows (but controls) iframes * Class definition for HTMLPurifier that allows (but controls) iframes
* @package chamilo.lib * @package chamilo.lib
@ -7,7 +15,7 @@
* Based on: http://stackoverflow.com/questions/4739284/htmlpurifier-iframe-vimeo-and-youtube-video * Based on: http://stackoverflow.com/questions/4739284/htmlpurifier-iframe-vimeo-and-youtube-video
* Iframe filter that does some primitive whitelisting in a somewhat recognizable and tweakable way * Iframe filter that does some primitive whitelisting in a somewhat recognizable and tweakable way
*/ */
class HTMLPurifier_Filter_AllowIframes extends HTMLPurifier_Filter class AllowIframes extends HTMLPurifier_Filter
{ {
public $name = 'AllowIframes'; public $name = 'AllowIframes';
@ -18,7 +26,7 @@ class HTMLPurifier_Filter_AllowIframes extends HTMLPurifier_Filter
* @param HTMLPurifier_Context $context * @param HTMLPurifier_Context $context
* @return string * @return string
*/ */
public function preFilter($html, HTMLPurifier_Config $config, HTMLPurifier_Context $context) public function preFilter($html, $config, $context)
{ {
$html = preg_replace('#<iframe#i', '<img class="MyIframe"', $html); $html = preg_replace('#<iframe#i', '<img class="MyIframe"', $html);
$html = preg_replace('#</iframe>#i', '</img>', $html); $html = preg_replace('#</iframe>#i', '</img>', $html);
@ -32,7 +40,7 @@ class HTMLPurifier_Filter_AllowIframes extends HTMLPurifier_Filter
* @param HTMLPurifier_Context $context * @param HTMLPurifier_Context $context
* @return string * @return string
*/ */
public function postFilter($html, HTMLPurifier_Config $config, HTMLPurifier_Context $context) public function postFilter($html, $config, $context)
{ {
$post_regex = '#<img class="MyIframe"([^>]+?)>#'; $post_regex = '#<img class="MyIframe"([^>]+?)>#';
return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html); return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html);

Loading…
Cancel
Save