classic asp ile tasarlanmış web sitenize kullanıcıların youtube videolarını mesaj alanına yazarak eklenmesini sağlayan ve hacklanme gibi durumları engelleyen basit sir okadarda kolay fonksiyon dosyasını paylaşıyorum. bu dosyayı web wiz forum alt yappısında kullanmıştır. bende ordan aldım. dosya içeriği aşağıdaki gibidir. <% dim strMessage dim oldMessage oldMessage="[TUBE]xq-aTe77bkA[/TUBE]" 'web sitenizde mesaj alanına kullanıcılar tarafından yazılan mesaj içeriği. strMessage=oldMessage 'This function formats YouTube Function formatYouTube(ByVal strMessage) 'Declare variables Dim strYouTubeLink 'Hold the You Tube Link Dim lngStartPos 'Holds search start postions Dim lngEndPos 'Holds end start postions Dim strBuildYouTube 'Holds the built coded message Dim strOriginalYouTube 'Holds the code block in original format 'Loop through all the BB codes in the message and convert to a link to the YouTube movie Do While InStr(1, strMessage, "[TUBE]", 1) > 0 AND InStr(1, strMessage, "[/TUBE]", 1) > 0
'Get the start and end of the YouTube BBcode lngStartPos = InStr(1, strMessage, "[TUBE]", 1) + 6 lngEndPos = InStr(lngStartPos, strMessage, "[/TUBE]", 1) 'Make sure the end position is not in error If lngEndPos < lngStartPos Then lngEndPos = lngStartPos + 6 'If there is a YouTube link then process If lngEndPos > lngStartPos Then 'Get the YouTube link strYouTubeLink = Trim(Mid(strMessage, lngStartPos, lngEndPos-lngStartPos))
'Replace watch?v= with v/ for those copy and pasting links strYouTubeLink = Replace(Trim(Mid(strMessage, lngStartPos, lngEndPos-lngStartPos)), "watch?v=", "v/")
'See if the YouTube link contains the whole URL or just the file name If InStr(1, strYouTubeLink, "http://", 1) = 0 Then strYouTubeLink = "http://www.youtube.com/v/" & strYouTubeLink
'Insert youTube movie strBuildYouTube = "<object width=""425"" height=""350""><param name=""movie"" value=""" & strYouTubeLink & """ /><param name=""allowScriptAccess"" value=""never"" /><param name=""allowNetworking"" value=""internal"" /><param name=""wmode"" value=""transparent"" /><embed src=""" & strYouTubeLink & """ type=""application/x-shockwave-flash"" allowScriptAccess=""never"" allowNetworking=""internal"" wmode=""transparent"" width=""425"" height=""350""></embed></object>" End If
'Get the start and end position in the start and end position in the message of the BBcode YouTube lngStartPos = InStr(1, strMessage, "[TUBE]", 1) lngEndPos = InStr(lngStartPos, strMessage, "[/TUBE]", 1) + 7 'Make sure the end position is not in error If lngEndPos < lngStartPos Then lngEndPos = lngStartPos + 6 'Get the original code to be replaced in the message strOriginalYouTube = Trim(Mid(strMessage, lngStartPos, lngEndPos-lngStartPos)) 'Replace the code codes in the message with the new formated code block If strBuildYouTube <> "" Then strMessage = Replace(strMessage, strOriginalYouTube, strBuildYouTube, 1, -1, 1) Else strMessage = Replace(strMessage, strOriginalYouTube, Replace(strOriginalYouTube, "[", "[", 1, -1, 1), 1, -1, 1) End If Loop 'Return the function formatYouTube = strMessage End Function If InStr(1, strMessage, "[TUBE]", 1) > 0 AND InStr(1, strMessage, "[/TUBE]", 1) > 0 Then strMessage = formatYouTube(strMessage) response.Write(oldMessage) response.Write("<br /><br /><br />") response.Write(strMessage) %> bu kod çalışmaktadır...... |
Bildirim