I was wondering if it's possible to enable javascript code in a specific forum (just like how html can be enabled). Reason is I'd like to be able to post streaming videos within a specific forum category. The code for the player looks like this:
<p id='preview'>The player will show in this paragraph</p>
<script type='text/javascript' src='swfobject.js'></script>
<script type='text/javascript'>
var s1 = new SWFObject('player.swf','player','400','300','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=video.flv');
s1.write('preview');
</script>
Is this possible?
Javascript is very dangerous - very easy for an attacker to potentially steal the admin session key (in other words, easy for them to log in as an admin account).
I suggest just making a custom MyCode for this instead.
Code:
\[video=(1?[0-9]{1,3})x(1?[0-9]{1,3})\]([^]'&"]+)\[/video\]
Replacement:
<p id='preview'>The player will show in this paragraph</p><script type='text/javascript' src='swfobject.js'></script><script type='text/javascript'>var s1 = new SWFObject('player.swf','player','$1','$2','9');s1.addParam('allowfullscreen','true');s1.addParam('allowscriptaccess','always');s1.addParam('flashvars','file=$3');s1.write('preview');</script>
(note, lack of new lines above is deliberate - also I suggest taking the script reference to swfobject.js out of the above and stick it in the header template instead to avoid duplication)
Interesting, I never worked with custom mycode
So you suggest to put this part of the script code:
<p id='preview'>The player will show in this paragraph</p><script type='text/javascript' src='swfobject.js'></script>
In the header part of the forum? If so, where exactly?
And put this code:
<script type='text/javascript'>var s1 = new SWFObject('player.swf','player','$1','$2','9');s1.addParam('allowfullscreen','true');s1.addParam('allowscriptaccess','always');s1.addParam('flashvars','file=$3');s1.write('preview');</script>
as custom mycode?
Edit:
I did the following:
My index template under Index Page Templates looks like this:
<html>
<head>
<title>{$mybb->settings['bbname']}</title>
{$headerinclude}
<script type="text/javascript">
<!--
lang.no_new_posts = "{$lang->no_new_posts}";
lang.click_mark_read = "{$lang->click_mark_read}";
// -->
</script>
<script type='text/javascript' src='swfobject.js'>
</script>
</head>
And added the custom MyCode. Tried calling up the video with either
[video=url] and [video]url[/video]
without success. I'm sure I'm doing something wrong.
(2009-02-08, 10:31 AM)zoog Wrote: [ -> ]So you suggest to put this part of the script code:
<p id='preview'>The player will show in this paragraph</p><script type='text/javascript' src='swfobject.js'></script>
In the header part of the forum? If so, where exactly?
Without the <p> tag, but looks like you figured it out.
(2009-02-08, 10:31 AM)zoog Wrote: [ -> ]And added the custom MyCode. Tried calling up the video with either [video=url] and [video]url[/video]
without success. I'm sure I'm doing something wrong.
You need to supply dimensions to the MyCode, like follows:
[video=400x300]video.flv[/video]
Probably should've forced a http:// prefix for the URL too, but it should be fine in most cases
Thanks for your help so far. I tried your suggestion, but not succesful yet
I used this to test
[video=400x300]http://www.tangodown.nl/data/streaming/video.flv[/video]
If I test it in the Custom MyCode settings the html code result seems to look alright, but the actual result rendering it in html gives nothing. Same if I test it in a post.
Maybe because the .js script part is not directly before the video itself? Or does it not matter?
Are you sure this is correct?
<script type='text/javascript' src='swfobject.js'>
</script>
swfobject.js has to be placed in the correct place.
Yes. Let me show:
this is the code I use in a test page to check if the script actually works:
<p id='preview'>The player will show in this paragraph</p>
<script type='text/javascript' src='http://www.tangodown.nl/global/mediaplayer/swfobject.js'></script>
<script type='text/javascript'>
var s1 = new SWFObject('http://www.tangodown.nl/global/mediaplayer/player.swf','player','400','300','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=http://www.tangodown.nl/data/streaming/video.flv');
s1.write('preview');
</script>
Which can be viewed at
www.tangodown.nl/streaming.php (as you can see the code works
)
This is what I've done (exactly) to make it work in the forum (in my previous posts I removed the complete url, but I'll copy/paste exactly what I have now).
Within the head part of the index template of my forum I have this:
<script type='text/javascript' src='http://www.tangodown.nl/global/mediaplayer/swfobject.js'>
</script>
The MyCode I added is this (without any hard breaks by using 'enter'):
<script type='text/javascript'>var s1 = new SWFObject('http://www.tangodown.nl/global/mediaplayer/player.swf','player','$1','$2','9');s1.addParam('allowfullscreen','true');s1.addParam('allowscriptaccess','always');s1.addParam('flashvars','file=$3');s1.write('preview');</script>
set for this expression:
\[video=(1?[0-9]{1,3})x(1?[0-9]{1,3})\]([^]'&"]+)\[/video\]
As far as I can see the code all adds up the same as in the streaming.php test page.
You need to have the <p> tag in the actual replacement. That is:
<p id='preview'>The player will show in this paragraph</p>
<script type='text/javascript'>var s1 = new SWFObject('http://www.tangodown.nl/global/mediaplayer/player.swf','player','$1','$2','9');s1.addParam('allowfullscreen','true');s1.addParam('allowscriptaccess','always');s1.addParam('flashvars','file=$3');s1.write('preview');</script>
BTW, if you didn't know, there will be issues if there are multiple instances of this on a single page.