Expanders::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Class Expanders
4
 *
5
 * @filesource   Expanders.php
6
 * @created      24.04.2018
7
 * @package      chillerlan\BBCode\Output\HTML
8
 * @author       smiley <[email protected]>
9
 * @copyright    2018 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\BBCode\Output\HTML;
14
15
class Expanders extends HTMLModuleAbstract{
16
17
	/**
18
	 * @var array
19
	 */
20
	protected $tags = ['expander', 'quote', 'spoiler', 'cw'];
21
22
	/**
23
	 * @return string
24
	 */
25
	protected function transform():string{
26
27
		if(empty($this->content)){
28
			return '';
29
		}
30
31
		$id = $this->randomID();
32
33
		return '<div class="'.$this->tag.'-container">'.
34
		       '<div data-id="'.$id.'" class="'.$this->tag.'-header expander"><span>'.$this->tag.': '.$this->getAttribute('desc').'</span></div>'. // @todo: desc in tag attribute
35
		       '<div id="'.$id.'" class="'.$this->tag.'-body" style="display:none;">'.$this->content.'</div>'.
36
		       '</div>';
37
	}
38
39
	/**
40
	 * @return string
41
	 */
42
	protected function quote():string{
43
44
		if(empty($this->content)){
45
			return '';
46
		}
47
48
		$id  = $this->randomID();
49
		$url = filter_var($this->getAttribute('url'), FILTER_VALIDATE_URL);
50
51
		// @todo
52
		return '<div class="quote-container">'.
53
		       '<div data-id="'.$id.'" class="quote-header expander">quote '.($this->getAttribute('source', null) ?? '').(!empty($url) ? ' <small>[<a href="'.$url.'">link</a>]<small>' : '').'</div>'.
54
		       '<blockquote id="'.$id.'" class="quote-body" style="display:block;">'.$this->content.'</blockquote>'. // @todo: collapse (js: collapse child elements etc.)
55
		       '</div>';
56
	}
57
58
}
59