Insert an specific iframe

Started by manudevil, April 04, 2023, 11:09:37 AM

Previous topic - Next topic

manudevil

Hello !

I wanted to know if such a plugin exist. I want to insert an iframe in a post. A friend of mine has developped a kind of calendar, and I need to insert his calendar in a post, using a pseudo code. Do you know if such a mod exist ?

Thank you in advance.

Aleksi "Lex" Kilpinen

If you are admin, and if you definitely trust the source you are loading it from, you can just use HTML BBC and any html-code inside a post.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Arantor

You as the admin can do so using the [html] bbcode, just use that bbcode and put your iframe in it.

Non admins will not be able to use the html bbcode for security reasons.
Holder of controversial views, all of which my own.


manudevil

Oh, good idea ! But I need it simpler, just with a pseudo code, if possible.
If you know a plugin that could do quite the same, I could use it like an inspiration, and modify it for my specific needs.

Sesquipedalian

There are many BBCode mods available that embed content into posts. Any of them could be used as inspiration.

Also, it is strongly recommended that you build your mod to use only integration hooks even if it is only for your own private use, so it would be best to take your inspiration from mods that are labelled as "Hooks Only" on the Customization site.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Arantor

I do have to ask why it needs to be "simpler".

I'm not even sure it actually *can* be meaningfully simpler. An iframe is one tag, it has its dimensions, it might have a few other things but it's still one line of code, put inside one bbcode.

Unless you're putting this in lots of posts, or you want to let other people post it in their posts, I'm honestly not sure it's worth the effort to wrap it in a "simple" bbcode.
Holder of controversial views, all of which my own.


manudevil

I need to insert the day of the calendar on the post of the day. Two posts by weeks, so... And not only the admin could do that.
I need to do that : https://forum.crazy-orc.org/index.php/board,3.0.html but for SMF 2.1.x

Arantor

And is the iframe code itself different every time?
Holder of controversial views, all of which my own.


manudevil

Slightly, we pass the date as parameter.

Arantor

So you've got to change it every time anyway... in the same way whether using a bbcode or not. Still might as well save the effort and just use what comes out of the box.

Or use the custom bbcode mod, should be able to do that but... you do already have all the tools you need and the saving isn't as great as might be imagined.
Holder of controversial views, all of which my own.


manudevil

Custom BBcode seems to be a great solution. I'll give it a try.
Thank you, you are very helpful. :)

manudevil

Alright. Custom BBcode didn't make the trick. So I developed my own plugin. But it is a little tricky for some details, I guess I need help. Is it here, or must I begin another topic ?

Thank you.


Arantor

Here's fine, what exactly do you need?
Holder of controversial views, all of which my own.


manudevil

I'm using the hook system to add a bbcode: [planificatorc]YYYY-MM-DD[/planificatorc]
Inside, there is obviously a date.
The mod changes the bbcode for an iframe, passing the date in parameter. In the iframe, there is a windows displaying informations on a specific calendar. And there is a Javascript script which allows the iframe to be the exact height of its content.
For that, I need a JS in the iframe, and a JS in the forum. It works well.
But...
How is it possible to load a JS script just once? If I load it on the function, it loads everytime we are using the bbcode...

Here is my PHP code:

<?php

/**
 * @package smfPlanificatorcFor2.1
 * @author GroumpH + ManuDevil
 * @version 0.3
 * @description Intégration du Planificatorc dans SMF v2.1.x
 */

 
if (!defined('SMF')) {
  die(
'No direct access...');
 }

/**
 * Intégration du pseudocode Dans chaque message
 * called by integrate_bbc_codes
 * uses http://davidjbradshaw.github.io/iframe-resizer/
 */
function planificatorc_bbc(&$codes, &$no_autolink_tags)
{
  
loadJavaScriptFile('iframeResizer.min.js');
  
$url "https://forum.crazy-orc.org/planificatorc/PlanningJour.php?date=$1";
  
$iframe '<iframe src="'.$url.'" frameborder="0" marginheight="1" marginwidth="1" style="width: 100%; height: 450px;"></iframe>';
  
$content = <<<HEREDOC
$iframe
<script>
/* http://davidjbradshaw.github.io/iframe-resizer/ */
var iframes = iFrameResize({
checkOrigin: false,
enablePublicMethods: true
});
</script>
HEREDOC;

  
$codes[] = array(
    
'tag' => 'planificatorc',
    
'type' => 'unparsed_content',
    
'content' => $content,
    
'block_level' => true,
  );
}

Thanks in advance!

Arantor

First line of the function should be:

static $loaded = false;

Then you can check if you have been loaded already:

if(!$loaded) {
  // call loadJavaScriptFile or whatever else is one time only
  $loaded = true
}

Making $loaded static means its value will be kept after each run so the first time, it gets set up to be false, checked that it is false, then you call loadJavaScriptFile (I'm on iPad, anything code is annoying!) then set $loaded to true, next time the function is called on that page, $loaded will still be true so won't trigger again.
Holder of controversial views, all of which my own.


manudevil

So simple and elegant.
Thank you, I soulda think of that myself. Brilliant!

Advertisement: