Completed
Push — master ( 1c7076...1224fd )
by Matt
06:03
created

bbcodes_config::hidden()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 8.8571
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 *
4
 * Advanced BBCode Box
5
 *
6
 * @copyright (c) 2018 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\abbc3\core;
12
13
use s9e\TextFormatter\Configurator;
14
15
/**
16
 * ABBC3 custom BBCodes configurator
17
 */
18
class bbcodes_config
19
{
20
	/**
21
	 * Configure s9e Pipes table plugin
22
	 *
23
	 * @param Configurator $configurator
24
	 * @access public
25
	 */
26 1
	public function pipes(Configurator $configurator)
27
	{
28 1
		if (!isset($configurator->BBCodes['pipes']))
29 1
		{
30 1
			return;
31
		}
32
33 1
		$configurator->plugins->load('PipeTables');
34
35
		// Add class "pipe-table" to allow us to style the table with our CSS
36 1
		$dom = $configurator->tags['TABLE']->template->asDOM();
37 1
		foreach ($dom->getElementsByTagName('table') as $table)
38
		{
39 1
			$table->setAttribute('class', 'pipe-table');
40 1
		}
41 1
		$dom->saveChanges();
42 1
	}
43
44
	/**
45
	 * Configure BBVideo to use the MEDIA tag with the Media Embed plugin
46
	 *
47
	 * @param Configurator $configurator
48
	 * @access public
49
	 */
50 1
	public function bbvideo(Configurator $configurator)
51
	{
52 1
		if (!isset($configurator->BBCodes['bbvideo']))
53 1
		{
54 1
			return;
55
		}
56
57
		// If MediaEmbed is not already active (for example due to another ext) lets enable it
58 1
		if (!isset($configurator->MediaEmbed) && !isset($configurator->BBCodes['MEDIA']))
59 1
		{
60 1
			foreach ($configurator->MediaEmbed->defaultSites as $tagName => $tag)
61
			{
62 1
				if (!isset($configurator->BBCodes[$tagName]))
63 1
				{
64 1
					$configurator->MediaEmbed->add($tagName);
65 1
				}
66 1
			}
67 1
		}
68
69 1
		unset($configurator->BBCodes['bbvideo'], $configurator->tags['bbvideo']);
70 1
		$configurator->BBCodes->add(
71 1
			'bbvideo',
72
			[
73 1
				'contentAttributes' => ['url'],
74
				'tagName'           => 'MEDIA'
75 1
			]
76 1
		);
77 1
	}
78
79
	/**
80
	 * Configure Hidden BBCode
81
	 *
82
	 * @param Configurator $configurator
83
	 * @access public
84
	 */
85 1
	public function hidden(Configurator $configurator)
86
	{
87 1
		if (!isset($configurator->BBCodes['hidden']))
88 1
		{
89 1
			return;
90
		}
91
92 1
		unset($configurator->BBCodes['hidden'], $configurator->tags['hidden']);
93 1
		$configurator->BBCodes->addCustom(
94 1
			'[hidden]{TEXT}[/hidden]',
95
			'<xsl:choose>
96
				<xsl:when test="$S_USER_LOGGED_IN and not($S_IS_BOT)">
97
					<div class="hidebox hidebox_visible">
98
						<div class="hidebox_title hidebox_visible">{L_ABBC3_HIDDEN_OFF}</div>
99
						<div class="hidebox_visible">{TEXT}</div>
100
					</div>
101 1
				</xsl:when>
102
				<xsl:otherwise>
103
					<div class="hidebox hidebox_hidden">
104
						<div class="hidebox_title hidebox_hidden">{L_ABBC3_HIDDEN_ON}</div>
105
						<div class="hidebox_hidden">{L_ABBC3_HIDDEN_EXPLAIN}</div>
106 1
					</div>
107
				</xsl:otherwise>
108
			</xsl:choose>'
109 1
		);
110 1
	}
111
}
112