Cheetah
LocalIframe.php
Go to the documentation of this file.
1 <?php
2 
4 {
5  public $name = 'LocalIframe';
6 
7  public function preFilter($sHtml, $config, $context)
8  {
9  if (strstr($sHtml, '<iframe')) {
10  $sHtml = str_ireplace("</iframe>", "", $sHtml);
11  if (preg_match_all("/<iframe(.*?)>/si", $sHtml, $aResult)) {
12  foreach ($aResult[1] as $key => $sItem) {
13  preg_match('/width="([0-9]+)"/', $sItem, $width);
14  $iWidth = $width[1];
15  preg_match('/height="([0-9]+)"/', $sItem, $height);
16  $iHeight = $height[1];
17  $sWsbUrl = preg_quote(CH_WSB_URL_ROOT);
18  $sIframeUrl = '';
19 echoDbgLog($sItem);
20  if (preg_match("#({$sWsbUrl}[a-zA-Z0-9_=\-\?\&\/]+)#", $sItem, $aMatches))
21  $sIframeUrl = $aMatches[1];
22  if (preg_match("#src=\"(((?!//)(?![a-z]+://)(?![a-z]+://))[a-zA-Z0-9_=\-\?\&\/]+)#", $sItem, $aMatches))
23  $sIframeUrl = $aMatches[1];
24 echoDbgLog($sIframeUrl);
25  if ($sIframeUrl)
26  $sHtml = str_replace($aResult[0][$key], '<img class="LocalIframe" width="' . $iWidth . '" height="' . $iHeight . '" src="' . $sIframeUrl . '">', $sHtml);
27  }
28  }
29  }
30  return $sHtml;
31  }
32 
33  public function postFilter($sHtml, $config, $context)
34  {
35  $sPostRegex = '#<img class="LocalIframe" ([^>]+)>#';
36  $sHtml = preg_replace_callback($sPostRegex, array($this, 'postFilterCallback'), $sHtml);
37  return $sHtml;
38  }
39 
40  protected function postFilterCallback($aMatches)
41  {
42  return '<iframe frameborder="0" allowfullscreen ' . $aMatches[1] . '></iframe>';
43  }
44 }
$config
$config
Definition: Filter.ExtractStyleBlocks.txt:33
$aResult
$aResult
Definition: index.php:19
php
HTMLPurifier_Filter_LocalIframe
Definition: LocalIframe.php:4
HTMLPurifier_Filter_LocalIframe\postFilterCallback
postFilterCallback($aMatches)
Definition: LocalIframe.php:40
HTMLPurifier_Filter
Definition: HTMLPurifier.standalone.php:5134
echoDbgLog
echoDbgLog($mWhat, $sDesc='', $sFileName='debug.log')
Definition: utils.inc.php:686
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
HTMLPurifier_Filter_LocalIframe\postFilter
postFilter($sHtml, $config, $context)
Definition: LocalIframe.php:33
HTMLPurifier_Filter_LocalIframe\$name
$name
Definition: LocalIframe.php:5
HTMLPurifier_Filter_LocalIframe\preFilter
preFilter($sHtml, $config, $context)
Definition: LocalIframe.php:7