לדלג לתוכן

יחידה:EmbedMedia: הבדלים בין גרסאות בדף

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית
יצירת דף עם התוכן "-- Module:EmbedMedia - גרסה מקיפה local p = {} function p.embed(frame) local url = frame.args.url or frame.args[1] local width = frame.args.width or "100%" local height = frame.args.height or "315" local autoplay = frame.args.autoplay == "true" and 1 or 0 local loop = frame.args.loop == "true" and 1 or 0 local muted = frame.args.muted == "true" and 1 or 0 if not url or url == "" then return '<span style="color:..."
תגיות: עריכה ממכשיר נייד עריכה דרך האתר הנייד עריכה מתקדמת מהנייד
 
אין תקציר עריכה
תגיות: עריכה ממכשיר נייד עריכה דרך האתר הנייד עריכה מתקדמת מהנייד
 
שורה 1: שורה 1:
-- Module:EmbedMedia - גרסה מקיפה
local p = {}
local p = {}


שורה 5: שורה 4:
     local url = frame.args.url or frame.args[1]
     local url = frame.args.url or frame.args[1]
     local width = frame.args.width or "100%"
     local width = frame.args.width or "100%"
     local height = frame.args.height or "315"
     local height = frame.args.height or "360"
     local autoplay = frame.args.autoplay == "true" and 1 or 0
     local autoplay = frame.args.autoplay == "true" and "autoplay" or ""
     local loop = frame.args.loop == "true" and 1 or 0
     local loop = frame.args.loop == "true" and "loop" or ""
     local muted = frame.args.muted == "true" and 1 or 0
     local muted = frame.args.muted == "true" and "muted" or ""


     if not url or url == "" then
     if not url or url == "" then
         return '<span style="color:red;">שגיאה: לא סופק קישור למדיה</span>'
         return '<span style="color:red;">שגיאה: לא סופק קישור למדיה</span>'
     end
     end
    local iframe_template = '<div style="position:relative;padding-bottom:56.25%%;height:0;overflow:hidden;"><iframe src="%s" width="100%%" height="100%%" style="position:absolute;top:0;left:0;width:100%%;height:100%%;" frameborder="0" allowfullscreen></iframe></div>'


     -- YouTube
     -- YouTube
     local yt_id = url:match("v=([%w%-_]+)") or url:match("youtu%.be/([%w%-_]+)")
     local yt_id = url:match("v=([%w%-_]+)") or url:match("youtu%.be/([%w%-_]+)")
     if yt_id then
     if yt_id then
         local yt_url = string.format("https://www.youtube.com/embed/%s?autoplay=%d&loop=%d&mute=%d", yt_id, autoplay, loop, muted)
         local embed_url = "https://www.youtube.com/embed/"..yt_id
        return string.format(iframe_template, yt_url)
        return string.format('<iframe width="%s" height="%s" src="%s" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', width, height, embed_url)
     end
     end


שורה 26: שורה 23:
     local vimeo_id = url:match("vimeo.com/(%d+)")
     local vimeo_id = url:match("vimeo.com/(%d+)")
     if vimeo_id then
     if vimeo_id then
         local vimeo_url = string.format("https://player.vimeo.com/video/%s?autoplay=%d&loop=%d&muted=%d", vimeo_id, autoplay, loop, muted)
         local embed_url = "https://player.vimeo.com/video/"..vimeo_id
        return string.format(iframe_template, vimeo_url)
        return string.format('<iframe width="%s" height="%s" src="%s" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>', width, height, embed_url)
     end
     end


     -- Dailymotion
     -- MP4
     local dm_id = url:match("dailymotion.com/video/([%w]+)")
     if url:match("%.mp4$") then
    if dm_id then
         return string.format('<video width="%s" height="%s" controls %s %s %s><source src="%s" type="video/mp4">דפדפן זה אינו תומך בהטמעת וידאו.</video>', width, height, autoplay, loop, muted, url)
         local dm_url = string.format("https://www.dailymotion.com/embed/video/%s?autoplay=%d&loop=%d&mute=%d", dm_id, autoplay, loop, muted)
        return string.format(iframe_template, dm_url)
     end
     end


     -- TikTok
     -- MP3
     if string.match(url, "tiktok.com") then
     if url:match("%.mp3$") then
         return string.format(iframe_template, url)
         return string.format('<audio controls %s %s %s><source src="%s" type="audio/mpeg">דפדפן זה אינו תומך בהטמעת שמע.</audio>', autoplay, loop, muted, url)
     end
     end


     -- SoundCloud
     -- SoundCloud (צריך iframe)
     if string.match(url, "soundcloud.com") then
     if url:match("soundcloud.com") then
         return string.format('<iframe width="100%%" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=%s&auto_play=%d"></iframe>', url, autoplay)
         return string.format('<iframe width="%s" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=%s"></iframe>', width, url)
    end
 
    -- Google Drive Video
    local drive_id = url:match("/file/d/([%w%-_]+)")
    if drive_id then
        local drive_embed = "https://drive.google.com/file/d/"..drive_id.."/preview"
        return string.format(iframe_template, drive_embed)
    end
 
    -- Slideshare
    if string.match(url, "slideshare.net") then
        return string.format('<iframe src="%s" width="100%%" height="500" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #ccc; border-width:1px; margin-bottom:5px; max-width:100%%;" allowfullscreen></iframe>', url)
    end
 
    -- MP4
    if string.match(url, "%.mp4$") then
        return string.format('<video width="%s" height="%s" controls autoplay="%d" loop="%d" muted="%d"><source src="%s" type="video/mp4">דפדפן זה אינו תומך בהטמעת וידאו.</video>', width, height, autoplay, loop, muted, url)
    end
 
    -- MP3
    if string.match(url, "%.mp3$") then
        return string.format('<audio controls autoplay="%d" loop="%d" muted="%d"><source src="%s" type="audio/mpeg">דפדפן זה אינו תומך בהטמעת שמע.</audio>', autoplay, loop, muted, url)
     end
     end


     -- ברירת מחדל: iframe רגיל
     return '<span style="color:red;">שגיאה: סוג מדיה לא נתמך</span>'
    return string.format(iframe_template, url)
end
end


return p
return p

גרסה אחרונה מ־16:52, 22 באוגוסט 2025

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:EmbedMedia/תיעוד

local p = {}

function p.embed(frame)
    local url = frame.args.url or frame.args[1]
    local width = frame.args.width or "100%"
    local height = frame.args.height or "360"
    local autoplay = frame.args.autoplay == "true" and "autoplay" or ""
    local loop = frame.args.loop == "true" and "loop" or ""
    local muted = frame.args.muted == "true" and "muted" or ""

    if not url or url == "" then
        return '<span style="color:red;">שגיאה: לא סופק קישור למדיה</span>'
    end

    -- YouTube
    local yt_id = url:match("v=([%w%-_]+)") or url:match("youtu%.be/([%w%-_]+)")
    if yt_id then
        local embed_url = "https://www.youtube.com/embed/"..yt_id
        return string.format('<iframe width="%s" height="%s" src="%s" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', width, height, embed_url)
    end

    -- Vimeo
    local vimeo_id = url:match("vimeo.com/(%d+)")
    if vimeo_id then
        local embed_url = "https://player.vimeo.com/video/"..vimeo_id
        return string.format('<iframe width="%s" height="%s" src="%s" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>', width, height, embed_url)
    end

    -- MP4
    if url:match("%.mp4$") then
        return string.format('<video width="%s" height="%s" controls %s %s %s><source src="%s" type="video/mp4">דפדפן זה אינו תומך בהטמעת וידאו.</video>', width, height, autoplay, loop, muted, url)
    end

    -- MP3
    if url:match("%.mp3$") then
        return string.format('<audio controls %s %s %s><source src="%s" type="audio/mpeg">דפדפן זה אינו תומך בהטמעת שמע.</audio>', autoplay, loop, muted, url)
    end

    -- SoundCloud (צריך iframe)
    if url:match("soundcloud.com") then
        return string.format('<iframe width="%s" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=%s"></iframe>', width, url)
    end

    return '<span style="color:red;">שגיאה: סוג מדיה לא נתמך</span>'
end

return p