1<?php
2
3/**
4* @package   s9e\TextFormatter
5* @copyright Copyright (c) 2010-2021 The s9e authors
6* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7*/
8namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator\TemplateGenerators;
9
10use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\TemplateGenerator;
11
12class Iframe extends TemplateGenerator
13{
14	/**
15	* @var array Default iframe attributes
16	*/
17	protected $defaultIframeAttributes = [
18		'allowfullscreen' => '',
19		'loading'         => 'lazy',
20		'scrolling'       => 'no',
21		'style'           => ['border' => '0']
22	];
23
24	/**
25	* @var string[] List of attributes to be passed to the iframe
26	*/
27	protected $iframeAttributes = ['allow', 'data-s9e-livepreview-ignore-attrs', 'data-s9e-livepreview-onrender', 'onload', 'scrolling', 'src', 'style'];
28
29	/**
30	* {@inheritdoc}
31	*/
32	protected function getContentTemplate()
33	{
34		$attributes = $this->mergeAttributes($this->defaultIframeAttributes, $this->getFilteredAttributes());
35
36		return '<iframe>' . $this->generateAttributes($attributes) . '</iframe>';
37	}
38
39	/**
40	* Filter the attributes to keep only those that can be used in an iframe
41	*
42	* @return array
43	*/
44	protected function getFilteredAttributes()
45	{
46		return array_intersect_key($this->attributes, array_flip($this->iframeAttributes));
47	}
48}