【问题标题】:How to force TinyMCE to use flash youtube embed instead of iframe?如何强制 TinyMCE 使用 flash youtube embed 而不是 iframe?
【发布时间】:2012-07-19 04:11:27
【问题描述】:

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

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

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

IE-

有没有办法做到两者之一:

  1. 更改嵌入文件/URL 字段时,修改 URL,以便默认嵌入 Flash 对象。 (http://www.youtube.com/watch?v=fWNaR-rxAic 将转换为http://www.youtube.com/v/fWNaR-rxAic
  2. 更改对 youtube 的调用,以便 youtube 返回 Flash 对象而不是 iFrame。

我的 TinyMCE 初始化代码是:

<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();
                        }
                    );
                }
        }
    );

</script>

谢谢,

【问题讨论】:

    标签: flash iframe youtube tinymce


    【解决方案1】:

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

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

    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;
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2012-09-23
      • 2019-04-21
      相关资源
      最近更新 更多