1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <?php
function embedder_replace($matches)
{
$temp = explode(' ', $matches[1]);
$count = count($temp);
$url = $temp[0];
$width = isset($temp[1]) ? $temp[1] : 200;
$height = isset($temp[2]) ? $temp[2] : 300;
$x = isset($temp[3]) ? $temp[3] : 0;
$y = isset($temp[4]) ? $temp[4] : 0;
if (strpos($width, 'px') === false and strpos($width, '%') === false)
{
$width .= 'px';
}
if (strpos($height, 'px') === false and strpos($height, '%') === false)
{
$height .= 'px';
}
if (get_option('embedder_scrollmethod') == '0')
{
$scrollTo1 = '';
$scrollTo2 = 'onload="scro11me(this)"></iframe>' .
'<script type="text/javascript">' .
'function scro11me(f){f.contentWindow.scrollTo(' . $x . ',' . $y . '); }' .
'</script>';
}
else
{
$scrollTo1 = '<div style="position:relative; overflow: hidden; width: ' . $width . '; height: ' . $height . '">' .
'<div style="position:absolute; left:' . (-1 * $x) . 'px; top: ' . (-1 * $y) . 'px">';
$scrollTo2 = '></iframe></div></div>';
$w = (int) $width;
$h = (int) $height;
$width = str_replace($w, $w + $x, $width);
$height = str_replace($h, $h + $x, $height);
}
return $scrollTo1 .
'<iframe class="' . get_option('embedder_class') . '" src="' . $url . '" style="width: ' .
$width . '; height: ' . $height . ';' . get_option('embedder_style') . ' " frameborder="' .
(int) get_option('embedder_border') . '" scrolling="' . get_option('embedder_scrolling') . '" ' .
$scrollTo2;
}
function embedder_parse_iframe($text)
{
return preg_replace_callback("@(?:<p>\s*)?\[iframe\s*(.*?)\](?:\s*</p>)?@", 'embedder_replace', $text);
}
add_filter('the_content', 'embedder_parse_iframe'); |
Partager