Is it possible to have a javascript in bbcode ?

Get help developing custom BBCodes or request one.
Post Reply
pitibonom
Registered User
Posts: 57
Joined: Thu Feb 09, 2012 3:59 pm

Is it possible to have a javascript in bbcode ?

Post by pitibonom »

Hi all :)

I was wondering wether it is possible to have a javascript script that is able to parse the {TEXT} or {URL} string and replace it with something coming from the javascript code ?

Thanks in advance and regards :)
Last edited by Mick on Mon May 16, 2022 7:13 am, edited 1 time in total.
Reason: Solved.
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26455
Joined: Fri Aug 29, 2008 9:49 am

Re: Is it possible to have a javascript in bbcode ?

Post by Mick »

Did you try it?
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
pitibonom
Registered User
Posts: 57
Joined: Thu Feb 09, 2012 3:59 pm

Re: Is it possible to have a javascript in bbcode ?

Post by pitibonom »

I did but am not even sure wether the JS code was executed or not...

It seems not but maybe i did things wrong ?

:?
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26455
Joined: Fri Aug 29, 2008 9:49 am

Re: Is it possible to have a javascript in bbcode ?

Post by Mick »

Please post the code you used along with an explanation of what it is you’re trying to do.
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
pitibonom
Registered User
Posts: 57
Joined: Thu Feb 09, 2012 3:59 pm

Re: Is it possible to have a javascript in bbcode ?

Post by pitibonom »

finally i managed to make it work fine :)

i only got a red alert on validating the bbcode, saying that using {TEXT} is a bad thing for security....

Here's my lil thingie that i share here:

BBCode:

Code: Select all

[Vid]{TEXT}[/Vid]
HTML:

Code: Select all

<div>
<iframe class="mediaContentBox" width="560" height="315" src="hop" allowfullscreen ></iframe>





<script>
var chaine = '{TEXT}';
var foundat=-1;

   if((foundat=chaine.toUpperCase().indexOf("https://odysee.com".toUpperCase())) != -1)
   {
      var adresse="none";

      var stringend = chaine.toUpperCase().indexOf('"',foundat);

      if(foundat==0 && stringend==-1)
         adresse = ""+chaine;
      else
         adresse = ""+chaine.substring(foundat,stringend);

      // grab the current element ( as there might be several of them in the page )
      var daddyElem =  document.currentScript.parentElement;

      // now get the iframe thingie ( there's only one per bbcode )
      var theThingToChange = daddyElem.getElementsByClassName("mediaContentBox")[0];

      // and finally change its src
      theThingToChange.src = adresse;

     // alert("base="+chaine+"\nstart="+foundat+"  end ="+stringend+"     url = "+adresse+" voila");
   }

</script>
</div>
I did this for video platforms embedding.
I see the whole community saying << there's mediaembed for this !!!! >>
yes but mediaembed works with an unusable and therefore useless regex pattern preventing anyone under +25 graduate to do anything.
And mediaembed do not handle platforms like francesoir odysee crowdbunker etc.... it appears therefore useless to me :(

Here what i do is far less academic but pretty straighforward: string search and that's all !
Of course this can be extended to any video platform you can imagine ;)

I hope you like it and will make it grow :D

I only have a small question:
Are BBCodes HTML limited in size in phpbb ( this would make sense by the way.... )

happy phpbbing !

EDIT: Oh and i was wrong ! javascript in BBCodes work like a charm :oops:
pitibonom
Registered User
Posts: 57
Joined: Thu Feb 09, 2012 3:59 pm

Re: Is it possible to have a javascript in bbcode ?

Post by pitibonom »

well...

I enhanced the script a bit so that i can now get rid of mediaembed :D

Code: Select all

    <div id="test">
    
        <iframe class="mediaContentBox" width="560" height="315" src="hop" allowfullscreen ></iframe>

        <script>
        
        var stringToParse='https://vimeo.com/565225040#t=60s';
        
        
           var convTable = [
           // str to find                             ,   str to set                              , from    , from
           //                                                                                       this      end
           //                                                                                       char      to
           //                                                                                       till      this
           //                                                                                       end       char
           ["https://odysee.com"                      ,""                                         ,''       ,''],
           ["https://crowdbunker.com/embed/"          ,""                                         ,''       ,''],
           ["https://www.youtube.com/watch"           ,"https://www.youtube-nocookie.com/embed/"  ,'='      ,''],
           ["https://youtu.be/"                       ,"https://www.youtube-nocookie.com/embed/"  ,''       ,'/'],
           ["https://www.youtube.com/embed/"          ,"https://www.youtube-nocookie.com/embed/"  ,''       ,'/'],
           ["https://www.youtube-nocookie.com/embed/" ,"https://www.youtube-nocookie.com/embed/"  ,''       ,'/'],
           ["https://vimeo.com/"                      ,"https://player.vimeo.com/video/"          ,''       ,'/']
           ];
           
           

           function ParseAndConvert(str,tabl)
           {
           var foundAt = -1;
           var retour  = "";
           
             // lets extract the actual url from passed str...
             if((foundAt=str.toUpperCase().indexOf(tabl[0].toUpperCase())) != -1)
             {
             var url = "";

                var stringEnd = str.toUpperCase().indexOf('"',foundAt);

                if(stringEnd == -1)
                   url = ""+str;
                else
                   url = ""+str.substring(foundAt,stringEnd);

                // okay here, we should have url containing the whole link...
                // lets rework it...
                // 1st check for the replacement string
							  if(tabl[1]!="")
                {
                   // here we should have chars to search for...
                   if(tabl[2]!='')// starting char
                   { // okay, let's find the starting char
                   var startCharPos=-1;
                   
                   
                      if((startCharPos=url.toUpperCase().indexOf(tabl[2].toUpperCase()))!=-1)
                      {
                         // the char was found lets build the return string
                         retour = ""+tabl[1]+url.substring(startCharPos+1);
                      }
                   }
                   else // no start char to search... maybe a char from string end ?       
                      if(tabl[3]!='')
                      { // let's find the ending char
                      var endCharPos=-1;
                      
                        if((endCharPos=url.toUpperCase().lastIndexOf(tabl[3].toUpperCase()))!=-1)
                        {
                           // the char was found lets build the return string
                           retour = ""+tabl[1]+url.substring(endCharPos+1);
                        }
                      }
                   
                }
                else
                { // no replacement string.... we'll return the whole url
                   retour = ""+url;
                }
              }
              
              return(retour);
           }
           
           
           var address="none";
           var idx=0;
           var found=false;
           while(found==false && idx < convTable.length)
           {
               address = ParseAndConvert(stringToParse,convTable[idx]);
               
               if(address!="")
                  found=true;
                  
               idx++;
           }
           
           if(found==false)
           {
              // lets copy the full string to address even if it don't work...
              address = ""+stringToParse;
           }
           

		      // grab the current element's parent ( as there might be several of them in the page )
		      var daddyElem =  document.currentScript.parentElement;

		      // now get the iframe thingie ( there's only one per bbcode )
		      var theThingToChange = daddyElem.getElementsByClassName("mediaContentBox")[0];

    		  // and finally change its src
		      theThingToChange.src = address;					

		     //alert("URL = "+address);

        </script>
    </div>
I hope you like it and add many many platforms :D

Happy phpbbing !
User avatar
Steve
Registered User
Posts: 1480
Joined: Tue Apr 07, 2009 7:48 pm
Name: Steven Clark
Contact:

Re: Is it possible to have a javascript in bbcode ?

Post by Steve »

var stringToParse='https://vimeo.com/565225040#t=60s'; direct link to a video...

""+str; append or prepend. Seems pointless. Zzzz

Bored, What was wrong with the media embed extension?
@ The Chief Medical Officers guideline for men is that: You are safest not to drink regularly more than 14 units per week.
- I drank that today++ :lol: 🍺
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26455
Joined: Fri Aug 29, 2008 9:49 am

Re: Is it possible to have a javascript in bbcode ?

Post by Mick »

Steve wrote: Mon May 16, 2022 2:20 pmdirect link to a video...
Yep, I thought that too.
pitibonom wrote: Sun May 15, 2022 6:20 pmusing {TEXT} is a bad thing for security
So you didn’t try {SIMPLETEXT}?

viewtopic.php?p=13742851#p13742851
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
pitibonom
Registered User
Posts: 57
Joined: Thu Feb 09, 2012 3:59 pm

Re: Is it possible to have a javascript in bbcode ?

Post by pitibonom »

@steve:
Sorry you're bored.
mediaembed is unusable when you want to add a new media.
For existing ones, it works like a charm !!!!!

but it's now 1+ year i tried to ( and asked for ) integrate odysee.com vids.
No solution and no answers ---> useless^^

Mine is better ( though less academic ) because it's straightforward and simple to understand and enhance.
This is as simple as this.
and the blah = ""+str is for visual typing. nothing more.

I write code since now 40 years. And what i'm sure of is that if noone can reuse it, it's simply shit !

mediaembed is a beautifull piece of coding art.
but if noone can use it....

@Mick:
SIMPLETEXT ??????
I never heard of this^^
I'll dig in it ASAP :)
thanks

Regards to all !
User avatar
warmweer
Jr. Extension Validator
Posts: 11194
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: Is it possible to have a javascript in bbcode ?

Post by warmweer »

Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
Steve
Registered User
Posts: 1480
Joined: Tue Apr 07, 2009 7:48 pm
Name: Steven Clark
Contact:

Re: Is it possible to have a javascript in bbcode ?

Post by Steve »

Come on then, please supply me your:

BBCode usage
HTML replacement

:D
@ The Chief Medical Officers guideline for men is that: You are safest not to drink regularly more than 14 units per week.
- I drank that today++ :lol: 🍺
pitibonom
Registered User
Posts: 57
Joined: Thu Feb 09, 2012 3:59 pm

Re: Is it possible to have a javascript in bbcode ?

Post by pitibonom »

@Steve:
It's nothing more than here: :)
viewtopic.php?p=15847691&sid=6400db97f5 ... #p15847691

You just have to replace the

Code: Select all

var stringToParse='https://vimeo.com/565225040#t=60s';
( wich is for testing ) with:

Code: Select all

var stringToParse='{TEXT}';
a small dumb func that search for things in submitted string and some few global code set up for each link.

Be sure that it's far more dirty than what is done in mediaembed !
But the aim of this is to make embedding 'user friendly' anything you want.
Finally with this lil piece of think i can embed francesoir.fr, crowdbunker, odysee, etc... videos

:)

EDIT: oh and BBCode is as simple as any other:
[Vid]blahblahblah[/Vid]
with 'blahblahblah' beeing the code given by video platforms for sharing videos in an iframe.
Post Reply

Return to “Custom BBCode Development and Requests”