1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8function wikiplugin_iframe_info()
9{
10	return [
11		'name' => tra('Iframe'),
12		'documentation' => 'PluginIframe',
13		'description' => tra('Include the body of another web page in a scrollable frame within a page'),
14		'prefs' => [ 'wikiplugin_iframe' ],
15		'body' => tra('URL'),
16		'format' => 'html',
17		'validate' => 'all',
18		'tags' => [ 'basic' ],
19		'iconname' => 'copy',
20		'introduced' => 3,
21		'params' => [
22			'name' => [
23				'safe' => true,
24				'required' => false,
25				'name' => tra('Name'),
26				'description' => tra('Name'),
27				'since' => '3.0',
28				'filter' => 'text',
29				'default' => '',
30			],
31			'title' => [
32				'safe' => true,
33				'required' => false,
34				'name' => tra('Title'),
35				'description' => tra('Frame title'),
36				'since' => '3.2',
37				'filter' => 'text',
38				'default' => '',
39			],
40			'width' => [
41				'safe' => true,
42				'required' => false,
43				'name' => tra('Width'),
44				'description' => tra('Width in pixels or %'),
45				'since' => '3.0',
46				'filter' => 'text',
47				'default' => '',
48			],
49			'height' => [
50				'safe' => true,
51				'required' => false,
52				'name' => tra('Height'),
53				'description' => tra('Pixels or %'),
54				'since' => '3.0',
55				'filter' => 'text',
56				'default' => '',
57			],
58			'align' => [
59				'safe' => true,
60				'required' => false,
61				'name' => tra('Alignment'),
62				'description' => tra('Align the iframe on the page'),
63				'since' => '3.0',
64				'filter' => 'word',
65				'default' => '',
66				'options' => [
67					['text' => '', 'value' => ''],
68					['text' => tra('Top'), 'value' => 'top'],
69					['text' => tra('Middle'), 'value' => 'middle'],
70					['text' => tra('Bottom'), 'value' => 'bottom'],
71					['text' => tra('Left'), 'value' => 'left'],
72					['text' => tra('Right'), 'value' => 'right']
73				]
74			],
75			'frameborder' => [
76				'safe' => true,
77				'required' => false,
78				'name' => tra('Frame Border'),
79				'description' => tra('Choose whether to show a border around the iframe'),
80				'since' => '3.0',
81				'filter' => 'digits',
82				'default' => '',
83				'options' => [
84					['text' => '', 'value' => ''],
85					['text' => tra('Yes'), 'value' => 1],
86					['text' => tra('No'), 'value' => 0]
87				]
88			],
89			'marginheight' => [
90				'safe' => true,
91				'required' => false,
92				'name' => tra('Margin Height'),
93				'description' => tra('Margin height in pixels'),
94				'since' => '3.0',
95				'filter' => 'digits',
96				'default' => '',
97			],
98			'marginwidth' => [
99				'safe' => true,
100				'required' => false,
101				'name' => tra('Margin Width'),
102				'description' => tra('Margin width in pixels'),
103				'since' => '3.0',
104				'filter' => 'digits',
105				'default' => '',
106			],
107			'scrolling' => [
108				'safe' => true,
109				'required' => false,
110				'name' => tra('Scrolling'),
111				'description' => tra('Choose whether to add a scroll bar'),
112				'since' => '3.0',
113				'filter' => 'word',
114				'default' => '',
115				'options' => [
116					['text' => '', 'value' => ''],
117					['text' => tra('Yes'), 'value' => 'yes'],
118					['text' => tra('No'), 'value' => 'no'],
119					['text' => tra('Auto'), 'value' => 'auto'],
120				]
121			],
122			'src' => [
123				'required' => false,
124				'name' => tra('URL'),
125				'description' => tra('URL'),
126				'filter' => 'url',
127				'since' => '3.0',
128				'default' => '',
129			],
130			'responsive' => [
131				'safe' => true,
132				'required' => false,
133				'name' => tra('Responsive'),
134				'description' => tra('Make the display responsive so that browsers determine dimensions based on the width of their containing block by creating an intrinsic ratio that will properly scale on any device.'),
135				'since' => '16.0',
136				'filter' => 'word',
137				'default' => '16by9',
138				'options' => [
139					['text' => '', 'value' => ''],
140					['text' => tra('16 by 9'), 'value' => '16by9'],
141					['text' => tra('4 by 3'), 'value' => '4by4'],
142					['text' => tra('no'), 'value' => 'no'],
143				]
144			],
145		],
146	];
147}
148
149function wikiplugin_iframe($data, $params)
150{
151
152	extract($params, EXTR_SKIP);
153	if (isset($responsive) and $responsive != 'no' and $responsive != 'n') {
154		if ($responsive == '4by3') {
155			$ret = '<div class="embed-responsive embed-responsive-4by3"><iframe class="embed-responsive-item" ';
156		} else {
157			$ret = '<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" ';
158		}
159	} else {
160		$ret = '<iframe ';
161	}
162
163	if (isset($name)) {
164		$ret .= " name=\"$name\"";
165	}
166	if (isset($title)) {
167		$ret .= " title=\"$title\"";
168	}
169	if (isset($width)) {
170		$ret .= " width=\"$width\"";
171	}
172	if (isset($height)) {
173		$ret .= " height=\"$height\"";
174	}
175	if (isset($align)) {
176		$ret .= " align=\"$align\"";
177	}
178	if (isset($frameborder)) {
179		$ret .= " frameborder=\"$frameborder\"";
180	}
181	if (isset($marginheight)) {
182		$ret .= " marginheight=\"$marginheight\"";
183	}
184	if (isset($marginwidth)) {
185		$ret .= " marginwidth=\"$marginwidth\"";
186	}
187	if (isset($scrolling)) {
188		$ret .= " scrolling=\"$scrolling\"";
189	}
190	if (isset($src)) {
191		$ret .= " src=\"$src\"";
192	} elseif (! empty($data)) {
193		$ret .= " src=\"$data\"";
194	}
195	if (strpos($src, 'ViewerJS') !== false) {
196		$ret .= " allowfullscreen webkitallowfullscreen";
197	}
198	if (isset($responsive) and $responsive != 'no' and $responsive != 'n') {
199		$ret .= ">$data</iframe></div>";
200	} else {
201		$ret .= ">$data</iframe>";
202	}
203	return $ret;
204}
205