如何强制TinyMCE使用YouTube嵌入式Flash代替iframe?

How to force TinyMCE to use flash youtube embed instead of iframe?

我正在使用TinyMCE 3.4.9,并试图强制媒体插件始终使用Flash嵌入而不是iFrame嵌入。

出于安全原因,我不想允许嵌入任何iFrame。

我已经手动格式化了URL,以获取Flash嵌入对象而不是iFrame对象。

IE-

  • 嵌入Flash:http://www.youtube.com/v/fWNaR-rxAic
  • 嵌入iFrame:

是否可以执行以下两种操作之一:

  • 更改嵌入文件/ URL字段后,请修改URL,以便默认情况下将嵌入Flash对象。 (http://www.youtube.com/watch?v=fWNaR-rxAic将转换为http://www.youtube.com/v/fWNaR-rxAic)
  • 将通话更改为youtube,以便youtube将返回Flash对象而不是iFrame。
  • 我的TinyMCE初始化代码是:

    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
    <script language="javascript" type="text/javascript">
        tinyMCE.init(
            {
                paste_remove_styles : true,
                gecko_spellcheck : true,
                theme_advanced_font_sizes :"1,2,3,4,5",
                extended_valid_elements:"script[charset|defer|language|src|type]",
                theme :"advanced",
                mode:"exact",
                plugins:"inlinepopups,emotions,searchreplace,paste,media",
                elements :"blogcontent",
                theme_advanced_toolbar_location :"top",
                theme_advanced_toolbar_align :"left",
                theme_advanced_buttons1 :"bold,italic,underline,strikethrough,sub,sup,|,fontselect,fontsizeselect,forecolor,|,link,unlink,|,backcolor",
                theme_advanced_buttons2 :"justifyleft,justifycenter,justifyright,|,search,replace,|,image,charmap,emotions, media,|,undo,redo",
                theme_advanced_buttons3 :"",
                theme_advanced_resize_horizontal : false,
                theme_advanced_resizing : false,
                file_browser_callback : 'file_browser',
                relative_urls : false,
                remove_script_host : false,
                paste_retain_style_properties :"font-size,color,font-family,background-color",
                setup :
                    function(ed)
                    {
                        ed.onKeyUp.add(
                            function(ed, e)
                            {
                                ed.nodeChanged();
                            }
                        );
                    }
            }
        );

    谢谢,


    由于我还没有找到强制Flash嵌入youtube视频的方法,因此我针对iframe安全问题创建了解决方法。

    我已将iframe添加到允许的标签列表中,并在保存后向用户显示内容,我对所有iframe应用了白名单过滤器,该过滤器会提取白名单中没有src的所有iframe。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    function filterIframeBySource($text, $allowed_sources)
    {
        // regex to retrieve just the iframes
        $regex      = '/<iframe[0-9a-zA-Z \\.\\/=>:\\-"]*<\\/iframe>/';
        $matches    = array();
        $reg_pos    = preg_match($regex, $text, $matches);

        // loop through each match and check the src for that iframe
        $src_expression = '/ src="http:\\/\\/('.str_replace('.', '\\.', implode('|', $allowed_sources)).')[0-9a-zA-Z\\/-]*" /';
        foreach($matches as $match)
        {
            $src_pos    = preg_match($src_expression, $match);

            if($src_pos !== false && $src_pos === 0)
                $text   = str_replace($match, '[Removed iFrame]', $text);
        }
        return $text;
    }

    希望这可以帮助。