Skip to content

Conversation

@jdarwood007
Copy link
Member

Fixes #7118

Syntax:

[youtube]sF80I-TQiW0[/youtube]
[youtube start=23363]sF80I-TQiW0[/youtube]

@Sesquipedalian
Copy link
Member

Sesquipedalian commented Oct 23, 2025

I don't think you need two versions of SMF\BBCode\YouTube. Instead, try this change in the existing YouTube class:

Find:

	/**
	 *
	 */
	public ?string $content = '<div class="videocontainer"><div><iframe frameborder="0" src="https://www.youtube.com/embed/$1?origin={hosturl}&wmode=opaque" data-youtube-id="$1" allowfullscreen loading="lazy"></iframe></div></div>';

	/**
	 *
	 */
	public ?string $disabled_content = '<a href="https://www.youtube.com/watch?v=$1" target="_blank" rel="noopener">https://www.youtube.com/watch?v=$1</a>';

Replace:

	/**
	 *
	 */
	public ?array $parameters = [
		'start' => [
			'match' => '(\d+)',
			'optional' => true,
			'default' => '0',
		],
	];

	/**
	 *
	 */
	public ?string $content = '<div class="videocontainer"><div><iframe frameborder="0" src="https://www.youtube.com/embed/$1?origin={hosturl}&wmode=opaque&start={start}" data-youtube-id="$1" allowfullscreen loading="lazy"></iframe></div></div>';

	/**
	 *
	 */
	public ?string $disabled_content = '<a href="https://www.youtube.com/watch?v=$1&t={start}s" target="_blank" rel="noopener">https://www.youtube.com/watch?v=$1&t={start}s</a>';

By making the start parameter optional and giving it a default value of 0, you can make [youtube]sF80I-TQiW0[/youtube] equivalent to [youtube start=0]sF80I-TQiW0[/youtube].

@jdarwood007
Copy link
Member Author

That would have an unintended side effect of making all the fallback URLs have "t=0s" in them.

@Sesquipedalian
Copy link
Member

That wouldn't hurt anything, as far as I can tell. 0s is the default for the t parameter in YouTube URLs anyway. But if you want to avoid it, you could add some logic to skip the URL param in the class's validate method.

Fixes SimpleMachines#7118

Syntax:
```
[youtube]sF80I-TQiW0[/youtube]
[youtube start=23363]sF80I-TQiW0[/youtube]
```
@Sesquipedalian Sesquipedalian merged commit cd0cc88 into SimpleMachines:release-3.0 Oct 26, 2025
7 checks passed
@jdarwood007 jdarwood007 deleted the 3.0/feature7118 branch October 26, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Time Code in youtube videos?

2 participants