Version: 1.1, by oasi
Developer Last Online: Dec 2008
Category: BB Code Enhancements -
Version: 3.7.x
Rating:
Released: 10-15-2008
Last Update: Never
Installs: 86
Re-useable Code Translations Is in Beta Stage
No support by the author.
Hi all
I've made a Custom BBcode to be able to insert any kind of google map into the forum posts, so the Plugins I tried were'nt working as we expected.
I post the code, I hope it can be useful for anyone.
Security problems, improvements and tunning will be apreciated...
I used the tag [gmap], and inside you have to copy the code for the HTML inclusion you can copy when you click the link icon in the map:
Code:
<script type="text/javascript">
function ckURL()
{ if ((u.indexOf("http://")!=u.lastIndexOf("http://"))||u.lastIndexOf("http://")!=0){return false;}
if (u.indexOf('"')>=0) {return false;}
if (u.indexOf("http://maps.google")!=0){return false;}
return true;
}
t='';incr=0;t_i="{param}";
t_n_q=t_i.replace(/"/g,'"');
if(t_n_q.indexOf("91;url")>0)
{ if(t_n_q.indexOf('91;url="')>0){t=t_n_q.substr(t_n_q.indexOf('91;url="')+8,t_n_q.length);t_n_q='';}
if(t_n_q.indexOf('91;url=')>0) {t=t_n_q.substr(t_n_q.indexOf('91;url=')+7,t_n_q.length);t_n_q='';a=t.replace(/93;/g,'"');t=a;incr=2;}
if(t_n_q.indexOf('91;url')>0) {if (t_n_q.indexOf('93;')==(t_n_q.indexOf('91;url')+8)){t=t_n_q.substr(t_n_q.indexOf('91;url')+11,t_n_q.length);a=t.replace(/91;/g,'"');t=a;}}
}
else
{ t=t_n_q.substr(t_n_q.indexOf('src="')+5,t_n_q.length);}
u=t.substr(0,t.indexOf('"')-incr);
up=u.replace(/amp;/g,'');u=up;
if (ckURL())
{ document.write('<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+u+'"></iframe>');}
else
{document.write("<p><b>Wrong map URL, edit the post to change it.</b></p>Reload the page when finished to check if correct.");}
</script>
The others settings for the BBCode are:
Use {option}: -> No Remove Tag If Empty -> Yes Disable BB Code Within This BB Code -> Yes Disable Smilies Within This BB Code -> Yes Disable Word Wrapping Within This BB Code ->Yes
Please, mark as installed if it worked and you are using it.
Hope it helps!
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
Love this code...did not notice the glich with IE until I read the whole thread. This worked for me....
Code:
<script type="text/javascript">
function checkURL()
{
if ((url.indexOf("http://")!=url.lastIndexOf("http://"))||url.lastIndexOf("http://")!=0){return false;}
if (url.indexOf('"')>=0) {return false;}
if (url.indexOf("http://maps.google")!=0){return false;}
return true
}
var browser=navigator.appName;
tot='{param}';
tot=tot.substr(tot.indexOf("src="")+10,tot.length);
url=tot.substr(0,tot.indexOf("""));
urlp=url.replace(/;amp;/g,';');
url=urlp;
if (checkURL())
{
document.write('<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+url.replace(/\[url\]|\[\\url\]/gi,"")+'"></iframe>');
}
else
{
document.write("<p><b>Wrong map URL, edit the post to change it.</b></p> Reload the page when finished to check if correct.");
}
</script>
The only change is in the document.write statement for iframe... changing +url+ to replace with a regular expression...no need to detect the browser since the replaced text does not exist when it is working.
Code:
url.replace(/\[url\]|\[\\url\]/gi,"")
I tried cleaning up the URL before the if statement but it kept failing. Adding the replace text directly in the document.write worked fine.
Great addon, thanks marked as installed and works fine on 3.8.3
One question, is it possible to add some code that will cause the link for directions to/from the point on the map to open in a new page/tab? At the moment if the find directions tab is clicked it loads in my forum tab.