1<?php
2/**
3 * Figure element component for the adhoctags plugin
4 *
5 * Defines  <figure> ... </figure> syntax
6 * More info: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Anika Henke <anika@selfthinker.org>
10 * @author     Sascha Leib <sascha.leib(at)kolmio.com>
11 */
12
13class syntax_plugin_adhoctags_img extends syntax_plugin_adhoctags_abstractblock {
14
15    protected $special_pattern = '<%t%\b[^>\r\n]*?>';
16	protected $tag	= 'img';
17
18	/* allow link attributes: */
19	function allowAttribute(&$name, &$value) {
20
21		switch ($name) {
22			case 'src':
23				return true; /* allow any URL! */
24				break;
25
26			case 'height':
27			case 'width':
28				return (preg_match('/^\d+$/', trim($value)));
29				break;
30
31			case 'crossorigin':
32				return in_array($value, array('anonymous','use-credentials'));
33				break;
34
35			case 'decoding':
36				return in_array($value, array('sync','async','auto'));
37				break;
38
39			case 'loading':
40				return in_array($value, array('eager','lazy'));
41				break;
42
43			case 'referrerpolicy':
44				return (preg_match('/^[\w\-]+$/', trim($value)));
45				break;
46
47			default:
48				return false;
49		}
50	}
51
52}
53
54